Skip to content

Commit 3ade543

Browse files
authored
Merge pull request #446 from krassowski/auto-clear-highlights
Allow to clear highlights on blur
2 parents a4f21ae + 92cc262 commit 3ade543

File tree

7 files changed

+47
-8
lines changed

7 files changed

+47
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## CHANGELOG
22

3-
### `@krassowski/jupyterlab-lsp 2.1.2` (2020-12-XX)
3+
### `@krassowski/jupyterlab-lsp 2.1.2` (2021-01-XX)
4+
5+
- features
6+
7+
- highlights can now be auto-removed from the cells/editors on blur (set `removeOnBlur` to `true` in settings) ([#446])
48

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])
@@ -9,6 +13,7 @@
913

1014
[#433]: https://github.com/krassowski/jupyterlab-lsp/issues/433
1115
[#434]: https://github.com/krassowski/jupyterlab-lsp/issues/434
16+
[#446]: https://github.com/krassowski/jupyterlab-lsp/issues/446
1217

1318
### `@krassowski/jupyterlab-lsp 2.1.1` (2020-12-15)
1419

atest/05_Features/Completion.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Completer Should Suggest
215215

216216
Completer Should Include Icon
217217
[Arguments] ${icon}
218-
Wait Until Page Contains Element ${COMPLETER_BOX} svg[data-icon="${icon}"]
218+
Wait Until Page Contains Element ${COMPLETER_BOX} svg[data-icon="${icon}"] timeout=10s
219219

220220
Completer Should Not Suggest
221221
[Arguments] ${text}

atest/05_Features/Highlights.robot

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,43 @@ Highlights are changed when moving cursor between cells
3737
Press Keys None DOWN # cursor to third cell, second line (`|test `)
3838
Should Highlight Token test
3939

40-
Highlights are added after typing
40+
Highlights are modified after typing
4141
Enter Cell Editor 1 line=2
42+
Press Keys None END # cursor after the token in second line (`test|`)
4243
Should Highlight Token test
43-
Press Keys None a
44+
Press Keys None a # cursor after the token in second line (`testa|`)
4445
Should Highlight Token testa
4546

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

5064
Should Highlight Token
51-
[Arguments] ${token} ${timeout}=10s
65+
[Arguments] ${token} ${timeout}=15s
5266
${token_element} Set Variable xpath://span[contains(@class, 'cm-lsp-highlight')][contains(text(), '${token}')]
5367
Wait Until Page Contains Element ${token_element} timeout=${timeout}
5468

5569
Should Not Highlight Token
56-
[Arguments] ${token} ${timeout}=10s
70+
[Arguments] ${token} ${timeout}=15s
5771
${token_element} Set Variable xpath://span[contains(@class, 'cm-lsp-highlight')][contains(text(), '${token}')]
5872
Wait Until Page Does Not Contain Element ${token_element} timeout=${timeout}
5973

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

atest/Keywords.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Open Context Menu for File
201201
Ensure File Browser is Open
202202
Click Element ${JLAB CSS REFRESH FILES}
203203
${selector} = Set Variable xpath://span[@class='jp-DirListing-itemText']\[text() = '${file}']
204-
Wait Until Page Contains Element ${selector}
204+
Wait Until Page Contains Element ${selector} timeout=10s
205205
Open Context Menu ${selector}
206206

207207
Rename Jupyter File

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)