diff options
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index d7c26cf..b2c4d54 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -347,13 +347,20 @@ const handleTypingInCodeBlock = (anchor) => { | |||
347 | const getSuggestions = (anchor) => { | 347 | const getSuggestions = (anchor) => { |
348 | let suggestions = [] | 348 | let suggestions = [] |
349 | const text = cm.getLine(anchor.line) | 349 | const text = cm.getLine(anchor.line) |
350 | const markInputIsInvalid = () => { | 350 | |
351 | // Clear marks on text | ||
352 | cm.findMarks( | ||
353 | { ...anchor, ch: 0 }, | ||
354 | { ...anchor, ch: text.length } | ||
355 | ).forEach(m => m.clear()) | ||
356 | |||
357 | // Mark user input invalid by case | ||
358 | const markInputIsInvalid = () => | ||
351 | cm.getDoc().markText( | 359 | cm.getDoc().markText( |
352 | { ...anchor, ch: 0 }, | 360 | { ...anchor, ch: 0 }, |
353 | { ...anchor, ch: -1 }, | 361 | { ...anchor, ch: text.length }, |
354 | { className: 'invalid-input' }, | 362 | { className: 'invalid-input' }, |
355 | ) | 363 | ) |
356 | } | ||
357 | 364 | ||
358 | // Check if "use: <renderer>" is set | 365 | // Check if "use: <renderer>" is set |
359 | const lineWithRenderer = getLineWithRenderer(anchor) | 366 | const lineWithRenderer = getLineWithRenderer(anchor) |
@@ -395,8 +402,8 @@ const getSuggestions = (anchor) => { | |||
395 | // If user is typing option | 402 | // If user is typing option |
396 | const keyTyped = text.split(':')[0].trim() | 403 | const keyTyped = text.split(':')[0].trim() |
397 | if (!isKeyFinished) { | 404 | if (!isKeyFinished) { |
398 | suggestions = getSuggestionsForOptions(keyTyped, validOptions) | ||
399 | markInputIsInvalid() | 405 | markInputIsInvalid() |
406 | return getSuggestionsForOptions(keyTyped, validOptions) | ||
400 | } | 407 | } |
401 | 408 | ||
402 | // If user is typing value | 409 | // If user is typing value |
@@ -409,13 +416,14 @@ const getSuggestions = (anchor) => { | |||
409 | const valueTyped = text.substring(text.indexOf(':') + 1).trim() | 416 | const valueTyped = text.substring(text.indexOf(':') + 1).trim() |
410 | const isValidValue = matchedOption.isValid(valueTyped) | 417 | const isValidValue = matchedOption.isValid(valueTyped) |
411 | if (!valueTyped) { | 418 | if (!valueTyped) { |
412 | suggestions = [ | 419 | return [ |
413 | getSuggestionFromMapOption(matchedOption), | 420 | getSuggestionFromMapOption(matchedOption), |
414 | ...getSuggestionsFromAliases(matchedOption) | 421 | ...getSuggestionsFromAliases(matchedOption) |
415 | ].filter(s => s instanceof Suggestion) | 422 | ].filter(s => s instanceof Suggestion) |
416 | } | 423 | } |
417 | if (valueTyped && !isValidValue) { | 424 | if (valueTyped && !isValidValue) { |
418 | markInputIsInvalid() | 425 | markInputIsInvalid() |
426 | return [] | ||
419 | } | 427 | } |
420 | } | 428 | } |
421 | 429 | ||
@@ -435,7 +443,7 @@ const getSuggestions = (anchor) => { | |||
435 | replace: `use: ${renderer}`, | 443 | replace: `use: ${renderer}`, |
436 | }) | 444 | }) |
437 | ) | 445 | ) |
438 | suggestions = rendererSuggestions.length > 0 ? rendererSuggestions : [] | 446 | return rendererSuggestions.length > 0 ? rendererSuggestions : [] |
439 | } | 447 | } |
440 | return suggestions | 448 | return suggestions |
441 | } | 449 | } |