From 9a95b06e74f71a67ddbf591496d8c12733b8bd7c Mon Sep 17 00:00:00 2001 From: Guillaume Dufour Date: Tue, 15 Oct 2024 19:40:53 +0200 Subject: [PATCH] fix #61 insert quote --- addon/data-load.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addon/data-load.js b/addon/data-load.js index 403886dd..48c4f99e 100644 --- a/addon/data-load.js +++ b/addon/data-load.js @@ -1337,9 +1337,15 @@ export class Editor extends React.Component { if (selectionStart != selectionEnd) { model.editor.setRangeText(closeChar, selectionEnd + 1, selectionEnd + 1, "preserve"); } else if ( + // If parenthesis, brace or bracket (e.key !== "'" && e.key !== "\"") - || (selectionEnd + 1 < model.editor.value.length && /[\w|\s]/.test(model.editor.value.substring(selectionEnd + 1, selectionEnd + 2))) - || selectionEnd + 1 === model.editor.value.length) { + // Or one side is a whitespace or a carriage return + || (selectionEnd + 1 < model.editor.value.length && /[\n|\s]/.test(model.editor.value.substring(selectionEnd + 1, selectionEnd + 2))) + || (selectionEnd > 0 && /[\n|\s]/.test(model.editor.value.substring(selectionEnd - 1, selectionEnd))) + // Or end of document + || selectionEnd + 1 === model.editor.value.length + // Or start of document + || selectionEnd === 0) { model.editor.setRangeText(closeChar, selectionEnd + 1, selectionEnd + 1, "preserve"); } }