Skip to content

Commit

Permalink
Fix region selection for 'feed region'
Browse files Browse the repository at this point in the history
  • Loading branch information
layus committed Dec 8, 2020
1 parent f9036c6 commit f155247
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit f155247

Please sign in to comment.