From f1552475d621b6ea5a59019f57e88953d153d6a9 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Tue, 8 Dec 2020 17:42:08 +0100 Subject: [PATCH] Fix region selection for 'feed region' --- src/extension.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7341b80..6b2e333 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -235,16 +235,23 @@ export function activate(context: vscode.ExtensionContext) { }); registerText('oz.feedParagraph', (textEditor) => { - let begin = textEditor.selection.start.line; - let end = begin; + let startLine = textEditor.selection.start.line; + let endLine = textEditor.selection.end.line; - while (begin > 0 - && !textEditor.document.lineAt(--begin).isEmptyOrWhitespace) { } - while (end < textEditor.document.lineCount - 1 - && !textEditor.document.lineAt(++end).isEmptyOrWhitespace) { } + while (startLine > 0 + && !textEditor.document.lineAt(startLine - 1).isEmptyOrWhitespace) { + startLine -= 1; + } + + while (endLine < textEditor.document.lineCount - 1 + && !textEditor.document.lineAt(endLine + 1).isEmptyOrWhitespace) { + endLine += 1; + } + + const startCharacter = 0; + const endCharacter = textEditor.document.lineAt(endLine).text.length; - let lastChar = textEditor.document.lineAt(end-1).range.end.character - let paragraph = new vscode.Selection(begin + 1, 0, end-1, lastChar); + let paragraph = new vscode.Selection(startLine, startCharacter, endLine, endCharacter); oz.send(textEditor.document.getText(paragraph), textEditor.document.fileName, paragraph.start); });