Comments (6)
I recently started using StandardNotes and hit this issue for Scala. Some thoughts are below. Assuming the below works for you, I can put together a PR if you want.
The clike languages aren't working since the individual language definitions are based on the mime type, which isn't stored on the note as far as I can tell. One fix would be to store the CodeMirror name
on the note instead of the mode
. This would require changing the dropdown list to a list of names and storing it in a name
attribute (or codeMirrorModeName
to avoid confusion with the title of the note).
The fun part would be migrating existing notes. If the existing note has a codeMirrorModeName
field, we're in the new state and can do CodeMirror.findModeByName
. If the existing note has a mode
field, we're in the old state. The CodeMirror API doesn't expose a findModeByMode
method, so we'll have to filter CodeMirror.modeInfo
ourselves. The latter is documented, so it should be safe to use.
Some questions:
-
If the old
mode
is on the note, we could either save the newcodeMirrorModeName
immediately (and I'm guessing indirectly modify the modified time), or wait for the user to change the note before saving. Former is easier, but latter is probably better UX. Thoughts? -
The existing code tries to do
findModeByExtension
andfindModeByMIME
if it thinks themode
is an extension or mime type. With the current code, when would either of those be the case? Am I missing some context when either of those would be saved as themode
?
from code-editor.
Hey @gshakhn, thanks for looking into this. Is it possible to just create a different mode for each clike language? https://github.com/sn-extensions/code-editor/tree/master/vendor/modes/clike
Duplication is fine, if it means not having to tinker with the architecture too much. It looks like we have some if/else to handle the different mime types. Any idea if it would be possible to isolate each one into a separate mode file?
from code-editor.
I was able to hack something together by:
- Copying the
clike
directory and renaming it toscala
. - Renaming
clike.js
toscala.js
. - Changing line 49 of
scala.js
fromCodeMirror.defineMode("clike",...
toCodeMirror.defineMode("scala",...
- Changing line 489 of
scala.js
from:
def("text/x-scala", {
name: "clike",
to
def("scala", {
name: "scala",
- Changing
{name: "Scala", mime: "text/x-scala", mode: "clike", ext: ["scala"]},
to{name: "Scala", mime: "text/x-scala", mode: "scala", ext: ["scala"]},
(I'm not sure if this was actually necessary. Did this early before tweaking the stuff below)
In theory it's possible. In practice, I wouldn't recommend this approach since this is fighting against how CodeMirror wants to work and will make upgrades more painful. Plus you'd be changing the mime type from text/x-scala
to scala
.
from code-editor.
Alternatively, you could also have a specific branch for each of the clike languages. e.g.
In changeMode
:
const actualMode = mode === 'scala' ? 'clike' : mode;
const actualSpec = mode === 'scala' ? 'text/x-scala' : spec;
editor.setOption("mode", actualSpec);
CodeMirror.autoLoadMode(editor, actualMode);
if (clientData) {
clientData.mode = mode;
}
document.getElementById("select").selectedIndex = modes.indexOf(mode);
When a new clike language is added, you would have to add an extra branch in addition to adding it to the modes
array. Given how often that happens, that's probably easier than my first suggested approach of migrating to storing the name
.
from code-editor.
Interesting. I don't have the capacity for this now, so I'll either take a look in the future, or feel free to submit a PR :)
from code-editor.
Submitted #3
from code-editor.
Related Issues (15)
- Path for /dist/vendor HOT 1
- No scrollbar in Code editor HOT 2
- Java does not actually have syntax highlighting HOT 1
- Code editor syntax highlighting doesn't work for 'Rust' HOT 2
- Update packages
- markdown - comments are treated as headings in code block HOT 2
- Ability to set default language HOT 1
- Vim mode for Code Editor doesn't seem to work well on Android
- Code editor issue on Android/iOS HOT 2
- Feature suggestion: allow changing code editor font size
- After enabling or disabling vim mode the focus should switch to the text in the editor
- Add README.md
- reStructuredText - no syntax highlighting HOT 3
- Unreadable text with highlight in some themes 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 code-editor.