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)
- Need to update mitigation of file editors `extensionFactory` issue before release
- IHaskell + HLS support HOT 2
- Consider using the `bin` field from `package.json` for specs derived from `NodeModuleSpec`
- Jupyterlab-lsp Error: Uncaught Exception GET /lsp/ws/pyls (::1) HOT 5
- jupyter_lsp - different location of jupyter-lsp-notebook.json between 2.2.2 and 2.2.3 HOT 3
- Markdown cells generate a lot of errors in browser logs and seem to block other extensions, like jupyterlab-spellchecker HOT 2
- GitHub release artifacts are not separate for jupyter-lsp and jupyterlab-lsp HOT 1
- Code Jump only in the same notebook HOT 4
- Plugin has no transformers yet. HOT 2
- JSON completion introduces unexpected character HOT 1
- Environment variables set for lsp servers leak into the server/kernel
- Define custom code extractors in settings HOT 4
- getting this error about `jupyter_lsp` HOT 2
- Auto completion do not need to click `Tab` HOT 2
- Renaming symbol empties all raw cells
- Whether to support monaco-editor using jupyterlab-lsp to implement multiple cells HOT 2
- No methods to use Tab instead of Enter to accept a suggestion in Jupyter LSP Code Completion? HOT 2
- Support basedpyright
- Support for the rename based on the whole project directory HOT 1
- Support for highlighting code by different color according to types like in VSCode HOT 1
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.