Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit dd7df85

Browse files
committed
Use addCommand for historyNavigation.
1 parent 05bf084 commit dd7df85

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

src/views/PromptComponent.tsx

+30-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class PromptComponent extends React.Component<Props, State> {
4040
fontSize: services.font.size * 1.2,
4141
fontFamily: services.font.family,
4242
suggestFontSize: services.font.size,
43-
minimap: { enabled: false },
43+
minimap: {enabled: false},
4444
scrollbar: {
4545
vertical: "hidden",
4646
horizontal: "hidden",
@@ -49,8 +49,30 @@ export class PromptComponent extends React.Component<Props, State> {
4949
quickSuggestions: true,
5050
quickSuggestionsDelay: 0,
5151
parameterHints: true,
52+
fontLigatures: true,
5253
});
5354

55+
this.editor.addCommand(
56+
monaco.KeyCode.UpArrow,
57+
() => this.setPreviousHistoryItem(),
58+
"!suggestWidgetVisible",
59+
);
60+
this.editor.addCommand(
61+
monaco.KeyMod.WinCtrl | monaco.KeyCode.KEY_P,
62+
() => this.setPreviousHistoryItem(),
63+
"!suggestWidgetVisible",
64+
);
65+
this.editor.addCommand(
66+
monaco.KeyCode.DownArrow,
67+
() => this.setNextHistoryItem(),
68+
"!suggestWidgetVisible",
69+
);
70+
this.editor.addCommand(
71+
monaco.KeyMod.WinCtrl | monaco.KeyCode.KEY_N,
72+
() => this.setNextHistoryItem(),
73+
"!suggestWidgetVisible",
74+
);
75+
5476
this.focus();
5577
}
5678

@@ -124,11 +146,14 @@ export class PromptComponent extends React.Component<Props, State> {
124146
}
125147
}
126148

127-
shouldNavigateHistory() {
128-
return this.state.displayedHistoryRecordID || this.editor.getValue() === "";
149+
setValue(value: string): void {
150+
this.editor.setValue(value);
151+
this.editor.setPosition({lineNumber: 1, column: value.length + 1});
152+
this.prompt.setValue(value);
153+
this.focus();
129154
}
130155

131-
setPreviousHistoryItem(): void {
156+
private setPreviousHistoryItem(): void {
132157
const currentID = this.state.displayedHistoryRecordID;
133158
if (currentID) {
134159
const currentRecord = services.history.get(currentID);
@@ -150,7 +175,7 @@ export class PromptComponent extends React.Component<Props, State> {
150175
}
151176
}
152177

153-
setNextHistoryItem(): void {
178+
private setNextHistoryItem(): void {
154179
const currentID = this.state.displayedHistoryRecordID;
155180
if (currentID) {
156181
const currentRecord = services.history.get(currentID);
@@ -168,13 +193,6 @@ export class PromptComponent extends React.Component<Props, State> {
168193
}
169194
}
170195

171-
setValue(value: string): void {
172-
this.editor.setValue(value);
173-
this.editor.setPosition({lineNumber: 1, column: value.length + 1});
174-
this.prompt.setValue(value);
175-
this.focus();
176-
}
177-
178196
private get promptContentNode(): HTMLDivElement {
179197
/* tslint:disable:no-string-literal */
180198
return this.refs["prompt-content"] as HTMLDivElement;

src/views/keyevents/Keybindings.ts

+5-21
Original file line numberDiff line numberDiff line change
@@ -356,37 +356,21 @@ export function handleUserEvent(application: ApplicationComponent, search: Searc
356356
return;
357357
}
358358

359-
if (event.keyCode === KeyCode.Tab && promptComponent.isInHistorySearch()) {
360-
promptComponent.applyHistorySearch();
361-
return;
362-
}
363-
364-
if (event.keyCode === KeyCode.Escape && promptComponent.isInHistorySearch()) {
365-
promptComponent.cancelHistorySearch();
366-
return;
367-
}
368-
369-
if (event.ctrlKey && event.keyCode === KeyCode.R) {
359+
if (event.ctrlKey && event.keyCode === KeyCode.R && !promptComponent.isInHistorySearch()) {
370360
promptComponent.startHistorySearch();
371361

372362
event.stopPropagation();
373363
event.preventDefault();
374364
return;
375365
}
376366

377-
if (promptComponent.shouldNavigateHistory() && isKeybindingForEvent(event, KeyboardAction.cliHistoryPrevious)) {
378-
promptComponent.setPreviousHistoryItem();
379-
380-
event.stopPropagation();
381-
event.preventDefault();
367+
if (event.keyCode === KeyCode.Tab && promptComponent.isInHistorySearch()) {
368+
promptComponent.applyHistorySearch();
382369
return;
383370
}
384371

385-
if (promptComponent.shouldNavigateHistory() && isKeybindingForEvent(event, KeyboardAction.cliHistoryNext)) {
386-
promptComponent.setNextHistoryItem();
387-
388-
event.stopPropagation();
389-
event.preventDefault();
372+
if (event.keyCode === KeyCode.Escape && promptComponent.isInHistorySearch()) {
373+
promptComponent.cancelHistorySearch();
390374
return;
391375
}
392376
}

tslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
],
3838
"no-any": false,
3939
"no-arg": true,
40-
"no-bitwise": true,
40+
"no-bitwise": false,
4141
"no-conditional-assignment": true,
4242
"no-consecutive-blank-lines": false,
4343
"no-console": [

0 commit comments

Comments
 (0)