Comments (6)
The setState
method will do that—but it always forces a full redraw of the document, so it may not be more efficient. (Though I guess buffer changes don't happen with a high enough frequency for that to matter terribly much.)
from dev.
At some point, I'll write docs with a number of examples, like these, but that's quite a bit off now because the API is entirely unstable for the near future.
Having multiple views on the same 'buffer' would work quite different in CM6 than it does in 5—the basic idea is to have separate editor states, but to apply changes made in one editor state to the other states that refer to the same document, so that the states' documents stay in sync.
from dev.
Thanks for outlining the basic idea of how it could work. That is very useful.
from dev.
FWIW I got this working. The solution I used keeps multiple views around, and just detaches and reattaches their DOM nodes as the "selected file" changes. The code looks something like this:
...
let selectedFileName;
const editorDiv = document.querySelector('#editor');
const setSelectedFileName = newSelectedFileName => {
if (selectedFileName) {
const oldView = viewForFileName(selectedFileName);
oldView.dom.remove();
}
const newView = viewForFileName(newSelectedFileName);
editorDiv.appendChild(newView.dom);
newView.dispatch(newView.state.transaction.scrollIntoView());
selectedFileName = newSelectedFileName;
};
...
This works pretty well, and it's fine for my particular use case of simulating and IDE sort of experience, but there may be a better way to do this. It may be possible to find a solution where the state instances for each "file" are tracked, while a single view instance gets re-used. I'm not sure how one might accomplish this with the new API.
from dev.
See codemirror/website@7f7f00e
from dev.
Awesome example! However it lacks the feature of selecting buffers. Is there any example that has this?
from dev.
Related Issues (20)
- bug: [Golang] Incorrect import declaration by auto completion HOT 1
- Linter example no longer works on Ubuntu 24.04? HOT 2
- Gboard doesn't delete text in Firefox HOT 7
- forceLinting() doesn't cancel pending linting HOT 5
- MergeView: crashes browser tab for large files HOT 2
- Built in browser search does not work for large documents HOT 3
- Scroll position shifts on click into the middle of a large document HOT 2
- Selection breaks if you drag outside of an iframe HOT 1
- Content not properly rendered when line contains many block widgets HOT 1
- CODE
- Xxx
- Codemirror/view 6.28.0 breaks newlines in chrome 126 HOT 8
- Selecting backwards throws errors with EditContext (6.28.0). HOT 4
- Setting `EditorView.editable.of(false)` does not work with EditContext API HOT 2
- After setting the error diagnostics by using setDiagnostics, when copying & pasting the complete text, the entire document prompts error. HOT 2
- placeholder with HTMLElement, when shared between multiple views, is only visible on one view
- codemirror/view 6.28.2 version will cause abnormal input of Chinese input method HOT 21
- python highlighting fails with initial blank line or comment HOT 4
- Programmatically fetch CodeMirror version HOT 1
- event `compositionstart ` was not triggered correctly HOT 3
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 dev.