Skip to content

Commit 47ec7a4

Browse files
committed
Merge branch 'development'
Release 0.7.6
2 parents 38439ef + 59919bf commit 47ec7a4

File tree

11 files changed

+136
-31
lines changed

11 files changed

+136
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.7.6 - 2024-08-23
8+
### Added
9+
- The text used for the instructions bar is now user-configurable using the new `CommandPaletteInstructionConfig` object
10+
11+
### Deprecated
12+
- `CommandPaletteConfig.showInstructions` is deprecated in favor of `CommandPaletteInstructionConfig.showInstructions`
13+
714
## 0.7.5 - 2024-08-08
815
### Changed
916
- Upgrade to Flutter 3.24

example/lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class _MyHomePageState extends State<MyHomePage> {
7070
// LogicalKeyboardKey.keyC,
7171
// ),
7272

73-
showInstructions: true,
73+
instructionConfig: CommandPaletteInstructionConfig(
74+
showInstructions: true,
75+
),
7476
),
7577
actions: [
7678
CommandPaletteAction.single(

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ packages:
4747
path: ".."
4848
relative: true
4949
source: path
50-
version: "0.7.5"
50+
version: "0.7.6"
5151
fake_async:
5252
dependency: transitive
5353
description:

lib/src/models/command_palette_config.dart

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore_for_file: public_member_api_docs, sort_constructors_first
21
import 'package:command_palette/src/controller/command_palette_controller.dart';
32
import 'package:command_palette/src/widgets/options/command_palette_body.dart';
43
import 'package:flutter/foundation.dart';
@@ -87,18 +86,15 @@ class CommandPaletteConfig {
8786

8887
/// Whether or not to show the instructions bar at the bottom of the command
8988
/// palette modal, under all the options.
90-
/// The current instructions tell the user how to user the modal with their
91-
/// keyboard
9289
///
93-
/// The current instructions are:
94-
/// * enter/return: to select, (or if an input action) to confirm
95-
/// * up/down arrow: to navigate
96-
/// * escape: to close
97-
///
98-
/// When a nested action is selected:
99-
/// * backspace: to cancel selected action
90+
/// This option is deprecated, prefer to use [instructionConfig] and set its
91+
/// property [CommandPaletteInstructionConfig.showInstructions]
10092
final bool showInstructions;
10193

94+
/// Configuration options for the instructions bar at the bottom of the
95+
/// command palette
96+
final CommandPaletteInstructionConfig instructionConfig;
97+
10298
CommandPaletteConfig({
10399
ActionFilter? filter,
104100
Key? key,
@@ -115,11 +111,15 @@ class CommandPaletteConfig {
115111
this.right,
116112
this.height,
117113
this.width,
114+
@Deprecated("Use CommandPaletteInstructionConfig.showInstructions instead")
118115
this.showInstructions = false,
116+
CommandPaletteInstructionConfig? instructionConfig,
119117
}) : filter = filter ?? kDefaultFilter,
120118
builder = builder ?? kDefaultBuilder,
121119
openKeySet = openKeySet ?? _defaultOpenKeySet,
122-
closeKeySet = closeKeySet ?? _defaultCloseKeySet;
120+
closeKeySet = closeKeySet ?? _defaultCloseKeySet,
121+
instructionConfig = instructionConfig ??
122+
CommandPaletteInstructionConfig(showInstructions: showInstructions);
123123

124124
@override
125125
bool operator ==(Object other) {
@@ -139,7 +139,9 @@ class CommandPaletteConfig {
139139
other.left == left &&
140140
other.right == right &&
141141
other.height == height &&
142-
other.width == width;
142+
other.width == width &&
143+
other.showInstructions == showInstructions &&
144+
other.instructionConfig == instructionConfig;
143145
}
144146

145147
@override
@@ -157,6 +159,85 @@ class CommandPaletteConfig {
157159
left.hashCode ^
158160
right.hashCode ^
159161
height.hashCode ^
160-
width.hashCode;
162+
width.hashCode ^
163+
showInstructions.hashCode ^
164+
instructionConfig.hashCode;
165+
}
166+
}
167+
168+
/// Configures the text and visibility of the instructions bar at the bottom of
169+
/// the command palette
170+
/// The current instructions tell the user how to user the modal with their
171+
/// keyboard
172+
///
173+
/// The current instructions are:
174+
/// * enter/return: to select, (or if an input action) to confirm
175+
/// * up/down arrow: to navigate
176+
/// * escape: to close
177+
///
178+
/// When a nested action is selected:
179+
/// * backspace: to cancel selected action
180+
class CommandPaletteInstructionConfig {
181+
/// Default value is "to confirm".
182+
/// Used with [CommandPaletteActionType.input] type actions to indicate to the
183+
/// user that the currently entered text can be submitted with the
184+
/// return/enter key
185+
final String confirmLabel;
186+
187+
/// Default value is "to select"
188+
/// Appears for all non input type action to indicate to the user that hitting
189+
/// the return/enter key will select the currently highlighted action
190+
final String selectLabel;
191+
192+
/// Default value is "to navigate"
193+
/// Tells the user the the up and down arrow keys can be used to highlight
194+
/// different actions in the command palette
195+
final String navigationLabel;
196+
197+
/// Default value is "to cancel selected action".
198+
/// Used with [CommandPaletteActionType.input] and
199+
/// [CommandPaletteActionType.nested] type actions, after that action has been
200+
/// select. Tells the user that pressing back-space will unselect the
201+
/// currently selected action
202+
final String cancelSelectedLabel;
203+
204+
/// Default value is "to close"
205+
/// Tells the user that the ESC key will close the command palette
206+
final String closeLabel;
207+
208+
/// Whether or not to show the instructions bar at the bottom of the command
209+
/// palette modal, under all the options.
210+
final bool showInstructions;
211+
212+
const CommandPaletteInstructionConfig({
213+
this.confirmLabel = "to confirm",
214+
this.selectLabel = "to select",
215+
this.navigationLabel = "to navigate",
216+
this.cancelSelectedLabel = "to cancel selected action",
217+
this.closeLabel = "to close",
218+
this.showInstructions = false,
219+
});
220+
221+
@override
222+
bool operator ==(Object other) {
223+
if (identical(this, other)) return true;
224+
225+
return other is CommandPaletteInstructionConfig &&
226+
other.confirmLabel == confirmLabel &&
227+
other.selectLabel == selectLabel &&
228+
other.navigationLabel == navigationLabel &&
229+
other.cancelSelectedLabel == cancelSelectedLabel &&
230+
other.closeLabel == closeLabel &&
231+
other.showInstructions == showInstructions;
232+
}
233+
234+
@override
235+
int get hashCode {
236+
return confirmLabel.hashCode ^
237+
selectLabel.hashCode ^
238+
navigationLabel.hashCode ^
239+
cancelSelectedLabel.hashCode ^
240+
closeLabel.hashCode ^
241+
showInstructions.hashCode;
161242
}
162243
}

lib/src/widgets/command_palette_instructions.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class CommandPaletteInstructions extends StatelessWidget {
1313
CommandPaletteControllerProvider.of(context);
1414
final outline = Theme.of(context).dividerColor;
1515
var color = controller.style.instructionColor;
16+
final instructionConfig = controller.config.instructionConfig;
1617
return Container(
1718
margin: const EdgeInsets.all(8.0),
1819
padding: const EdgeInsets.only(top: 8),
@@ -38,8 +39,8 @@ class CommandPaletteInstructions extends StatelessWidget {
3839
instruction:
3940
(controller.currentlySelectedAction?.actionType ==
4041
CommandPaletteActionType.input)
41-
? "to confirm"
42-
: "to select",
42+
? instructionConfig.confirmLabel
43+
: instructionConfig.selectLabel,
4344
),
4445
if (controller.currentlySelectedAction?.actionType !=
4546
CommandPaletteActionType.input)
@@ -54,7 +55,7 @@ class CommandPaletteInstructions extends StatelessWidget {
5455
color: color,
5556
),
5657
],
57-
instruction: "to navigate",
58+
instruction: instructionConfig.navigationLabel,
5859
),
5960
if (controller.currentlySelectedAction != null)
6061
_KeyboardInstruction(
@@ -64,7 +65,7 @@ class CommandPaletteInstructions extends StatelessWidget {
6465
color: color,
6566
),
6667
],
67-
instruction: "to cancel selected action",
68+
instruction: instructionConfig.cancelSelectedLabel,
6869
),
6970
_KeyboardInstruction(
7071
icons: [
@@ -73,7 +74,7 @@ class CommandPaletteInstructions extends StatelessWidget {
7374
color: color,
7475
),
7576
],
76-
instruction: "to close",
77+
instruction: instructionConfig.closeLabel,
7778
),
7879
],
7980
),

lib/src/widgets/options/command_palette_body.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class _CommandPaletteBodyState extends State<CommandPaletteBody> {
9595
},
9696
),
9797
),
98-
if (controller.config.showInstructions)
98+
if (controller.config.instructionConfig.showInstructions)
9999
const CommandPaletteInstructions(),
100100
],
101101
),

pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ packages:
5858
dependency: "direct dev"
5959
description:
6060
name: flutter_lints
61-
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
61+
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
6262
url: "https://pub.dev"
6363
source: hosted
64-
version: "3.0.1"
64+
version: "4.0.0"
6565
flutter_test:
6666
dependency: "direct dev"
6767
description: flutter
@@ -95,10 +95,10 @@ packages:
9595
dependency: transitive
9696
description:
9797
name: lints
98-
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
98+
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
9999
url: "https://pub.dev"
100100
source: hosted
101-
version: "3.0.0"
101+
version: "4.0.0"
102102
matcher:
103103
dependency: transitive
104104
description:

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: command_palette
22
description: Flutter implementation of a Command Palette. Can be brought up via a keyboard shortcut.
3-
version: 0.7.5
3+
version: 0.7.6
44
homepage: https://github.com/TNorbury/command_palette
55
issue_tracker: https://github.com/TNorbury/command_palette/issues
66
repository: https://github.com/TNorbury/command_palette
@@ -26,7 +26,7 @@ dependencies:
2626
dev_dependencies:
2727
flutter_test:
2828
sdk: flutter
29-
flutter_lints: ^3.0.1
29+
flutter_lints: ^4.0.0
3030

3131
flutter:
3232

test/command_palette_instructions_test.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ void main() {
2121
[
2222
action,
2323
],
24-
config: CommandPaletteConfig(showInstructions: true),
24+
config: CommandPaletteConfig(
25+
instructionConfig: const CommandPaletteInstructionConfig(
26+
showInstructions: true,
27+
),
28+
),
2529
);
2630

2731
controller.currentlySelectedAction = action;
@@ -49,7 +53,11 @@ void main() {
4953
],
5054
),
5155
],
52-
config: CommandPaletteConfig(showInstructions: true),
56+
config: CommandPaletteConfig(
57+
instructionConfig: const CommandPaletteInstructionConfig(
58+
showInstructions: true,
59+
),
60+
),
5361
);
5462

5563
await tester.pumpWidget(

test/command_palette_options_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ void main() {
148148
// setting flag will show instructions
149149
await tester.pumpWidget(
150150
MyApp(
151-
config: CommandPaletteConfig(showInstructions: true),
151+
config: CommandPaletteConfig(
152+
instructionConfig: const CommandPaletteInstructionConfig(
153+
showInstructions: true,
154+
),
155+
),
152156
actions: [
153157
CommandPaletteAction.single(
154158
label: "Action 1",

0 commit comments

Comments
 (0)