Comments (3)
Here is a previous bug of this nature that was filled against CM6 by yours truly: https://discuss.codemirror.net/t/how-to-add-decoration-without-focusing-the-editor-on-dispatch/6283
from jupyterlab-lsp.
Ok, I do not see a downstream solution. JupyterLab 4.1 might help here because it will make it impossible to focus on the notebook node but not sure if this will fix the issue. Manual refocusing nor any attempt to partially disable the updates does not solve the issue. The way forward is to create reproducer and report this upstream.
from jupyterlab-lsp.
Cannot reproduce it yet in the latest playground it is possible that we just need to update codemirror vesions.
import { Decoration, EditorView, keymap } from "@codemirror/view"
import { StateField, StateEffect } from "@codemirror/state"
const addUnderline = StateEffect.define({
map: ({from, to}, change) => ({from: change.mapPos(from), to: change.mapPos(to)})
})
const removeMark = StateEffect.define();
const underlineField = StateField.define({
create() {
return Decoration.none
},
update(underlines, tr) {
underlines = underlines.map(tr.changes)
for (let e of tr.effects) {
if (e.is(addUnderline)) {
underlines = underlines.update({
add: [underlineMark.range(e.value.from, e.value.to)]
});
} else if (e.is(removeMark)) {
underlines = underlines.update({
filter: (from, to, value) => {
return false
}
});
}
}
return underlines
},
provide: f => EditorView.decorations.from(f)
})
const underlineMark = Decoration.mark({class: "cm-underline"})
const underlineTheme = EditorView.baseTheme({
".cm-underline": { textDecoration: "underline 3px red" }
})
const views = new Set();
function underlineSelection(view) {
let effects = view.state.selection.ranges
.filter(r => !r.empty)
.map(({from, to}) => addUnderline.of({from, to}))
if (!effects.length) return false
if (!view.state.field(underlineField, false))
effects.push(StateEffect.appendConfig.of([underlineField,
underlineTheme]))
view.dispatch({effects});
views.add(view);
return true
}
function clearAllUnderlines(_view) {
for (let view of views) {
const effects = [removeMark.of(null)];
view.dispatch({effects});
}
views.clear();
return true
}
export const underlineKeymap = keymap.of([
{
key: "Mod-h",
preventDefault: true,
run: underlineSelection
},
{
key: "Mod-j",
preventDefault: true,
run: clearAllUnderlines
}
])
const div1 = document.createElement('div');
const div2 = document.createElement('div');
div1.style.height = '100px'
div2.style.height = '100px'
document.body.appendChild(div1);
document.body.appendChild(div2);
new EditorView({
doc: "Select text and press Ctrl-h (Cmd-h) to add an underline\nto it.\n",
extensions: [underlineKeymap],
parent: div1
});
new EditorView({
doc: "Select text and press Ctrl-h (Cmd-h) to add an underline\nto it.\n",
extensions: [underlineKeymap],
parent: div2
});
setTimeout(() => {
console.log('active element before clear:', document.activeElement)
clearAllUnderlines(null)
console.log('active element after clear:', document.activeElement)
}, 5 * 1000)
from jupyterlab-lsp.
Related Issues (20)
- Support outside Jupyter environment HOT 1
- Number of characters displayed on the autocompletion box HOT 2
- Set up problems with python-lsp-ruff HOT 5
- Could not determine npm prefix: [WinError 2] The system cannot find the file specified HOT 4
- jump-to-definition gives File Load Error when using pyright as the language server even if the file is inside the root contents directory HOT 5
- no completion for console
- Renaming symbol empties all Markdown cells HOT 3
- tab-key code completion with julia HOT 1
- Continuous hinting doesn't work HOT 10
- [Feature request] Implement LSP 3.17 notebook document support HOT 1
- IPython kernel autocompletions (some) stop working after installing LSP HOT 4
- The `jlpm bootstrap` looks not to be working. HOT 1
- `smoke windows pypypy-3.8` fails HOT 1
- Language server keeps waiting HOT 1
- LSP for slow-starting (remote) kernels HOT 4
- 5.0.1: pytest fails on scanning units with call trace
- Add `_jupyter_server_extension_points` in `__init__.py`
- I hope i can perform code completions like Rstudio HOT 5
- Tests which need work after 5.0 release
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupyterlab-lsp.