Skip to content

Commit 1fc7202

Browse files
committed
Allow to clear highlights on blur
1 parent 87b0f93 commit 1fc7202

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
### `@krassowski/jupyterlab-lsp 2.1.2` (2020-12-XX)
44

5+
- features
6+
7+
- highlights can now be auto-removed from the cells/editors on blur (set `removeOnBlur` to `true` in settings) ([#446])
8+
59
- bug fixes
610
- improved performance of completion and highlights by minimising the number of highlight requests and GUI redraws (token checking, debouncing, acting on a single response only) ([#433])
711
- highlights now update after cell focus/blur events even if those do not trigger cursor movement ([#433])
812

913
[#433]: https://github.com/krassowski/jupyterlab-lsp/issues/433
14+
[#446]: https://github.com/krassowski/jupyterlab-lsp/issues/446
1015

1116
### `@krassowski/jupyterlab-lsp 2.1.1` (2020-12-15)
1217

atest/05_Features/Highlights.robot

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ Highlights are added after typing
4343
Press Keys None a
4444
Should Highlight Token testa
4545

46+
Highlights are removed when no cell is focused
47+
Enter Cell Editor 1 line=2
48+
# Remove when turned on
49+
Configure JupyterLab Plugin {"removeOnBlur": true} plugin id=${HIGHLIGHTS PLUGIN ID}
50+
Should Highlight Token test
51+
Blur Cell Editor 1
52+
Should Not Highlight Any Tokens
53+
# Do not remove when turned off
54+
Configure JupyterLab Plugin {"removeOnBlur": false} plugin id=${HIGHLIGHTS PLUGIN ID}
55+
Should Highlight Token test
56+
Blur Cell Editor 1
57+
Should Highlight Token test
58+
4659
*** Keywords ***
4760
Should Not Highlight Any Tokens
4861
Page Should Not Contain css:.cm-lsp-highlight
@@ -59,3 +72,7 @@ Should Not Highlight Token
5972

6073
Setup Highlights Test
6174
Setup Notebook Python Highlights.ipynb
75+
76+
Blur Cell Editor
77+
[Arguments] ${cell_nr}
78+
Click Element css:.jp-Cell:nth-child(${cell_nr}) .jp-InputPrompt

atest/Variables.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ${CM CURSORS} css:.jp-MainAreaWidget:not(.lm-mod-hidden) .CodeMirror-cursors
4545
# settings
4646
${LSP PLUGIN ID} @krassowski/jupyterlab-lsp:plugin
4747
${COMPLETION PLUGIN ID} @krassowski/jupyterlab-lsp:completion
48+
${HIGHLIGHTS PLUGIN ID} @krassowski/jupyterlab-lsp:highlights
4849
${JUMP PLUGIN ID} @krassowski/jupyterlab-lsp:jump_to
4950
${DIAGNOSTICS PLUGIN ID} @krassowski/jupyterlab-lsp:diagnostics
5051
${CSS USER SETTINGS} .jp-SettingsRawEditor-user

packages/jupyterlab-lsp/schema/highlights.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"type": "number",
1111
"default": 250,
1212
"description": "Number of milliseconds to delay sending out the highlights request to the language server; you can get better responsiveness adjusting this value, but setting it to zero can actually slow it down as the server might get overwhelmed when moving the cursor."
13+
},
14+
"removeOnBlur": {
15+
"title": "Remove highlights on editor (e.g. cell) blur",
16+
"type": "boolean",
17+
"default": false,
18+
"description": "Whether the highlights should disappear after the focus leaves the editor/cell"
1319
}
1420
},
1521
"jupyter.lab.shortcuts": []

packages/jupyterlab-lsp/src/features/highlights.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ export class HighlightsCM extends CodeMirrorIntegration {
6565
this.debounced_get_highlight = this.create_debouncer();
6666
});
6767
this.editor_handlers.set('cursorActivity', this.onCursorActivity);
68-
this.editor_handlers.set('blur', this.onCursorActivity);
68+
this.editor_handlers.set('blur', this.onBlur);
6969
this.editor_handlers.set('focus', this.onCursorActivity);
7070
super.register();
7171
}
7272

73+
protected onBlur = () => {
74+
if (this.settings.composite.removeOnBlur) {
75+
this.clear_markers();
76+
this.last_token = null;
77+
} else {
78+
this.onCursorActivity().catch(console.warn);
79+
}
80+
};
81+
7382
remove(): void {
7483
this.handleHighlight = null;
7584
this.onCursorActivity = null;

0 commit comments

Comments
 (0)