From 63918e1f5aa0fc5dc5734724690e92d9bd158360 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Fri, 30 Mar 2018 00:04:55 -0500 Subject: [PATCH] Fix option detection vatlab/sos-notebook#52 --- src/codemirror-sos.ts | 20 +++++++++++--------- src/sos-mode.js | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/codemirror-sos.ts b/src/codemirror-sos.ts index b1e6e83..348b7af 100644 --- a/src/codemirror-sos.ts +++ b/src/codemirror-sos.ts @@ -405,18 +405,20 @@ CodeMirror.defineMode("sos", function(conf: CodeMirror.EditorConfiguration, pars if (stream.peek() == ',') { // move next stream.next(); - // , is not the last char, end option line - if (!stream.eol()) { - state.sos_state = null; - state.inner_mode = null; + // , is the last char, continue option line + if (stream.eol()) { + stream.backUp(1); + let it = base_mode.token(stream, state.base_state); + return it ? it + ' sos-option' : null; } stream.backUp(1); - let it = base_mode.token(stream, state.base_state); - return it ? it + ' sos-option' : null; - } else { - let it = base_mode.token(stream, state.base_state); - return it ? it + ' sos-option' : null; + } else if (stream.eol()) { + // end of line stops option mode + state.sos_state = null; + state.inner_mode = null; } + let it = base_mode.token(stream, state.base_state); + return it ? it + ' sos-option' : null; } else if (state.sos_state && state.sos_state.startsWith("start ")) { let sl = stream.peek(); let token = base_mode.token(stream, state.base_state); diff --git a/src/sos-mode.js b/src/sos-mode.js index f743517..3b5e0ab 100644 --- a/src/sos-mode.js +++ b/src/sos-mode.js @@ -411,18 +411,20 @@ if (stream.peek() == ',') { // move next stream.next(); - // , is not the last char, end option line - if (!stream.eol()) { - state.sos_state = null; - state.inner_mode = null; + // , is the last char, continue option line + if (stream.eol()) { + stream.backUp(1); + let it = base_mode.token(stream, state.base_state); + return it ? it + ' sos-option' : null; } stream.backUp(1); - let it = base_mode.token(stream, state.base_state); - return it ? it + ' sos-option' : null; - } else { - let it = base_mode.token(stream, state.base_state); - return it ? it + ' sos-option' : null; + } else if (stream.eol()) { + // end of line stops option mode + state.sos_state = null; + state.inner_mode = null; } + let it = base_mode.token(stream, state.base_state); + return it ? it + ' sos-option' : null; } else if (state.sos_state && state.sos_state.startsWith("start ")) { let sl = stream.peek(); let token = base_mode.token(stream, state.base_state);