diff --git a/src/editorsupport.ts b/src/editorsupport.ts index 4385988..09d768f 100644 --- a/src/editorsupport.ts +++ b/src/editorsupport.ts @@ -8,16 +8,20 @@ export class BlockDetector { const position = this.editor.selection.active; const doc = this.editor.document; - let startLine = doc.lineAt(position.line-1); - let endLine = doc.lineAt(position.line); - - while (!startLine.isEmptyOrWhitespace && startLine.lineNumber > 0) { - startLine = doc.lineAt(startLine.lineNumber-1) - } - if (startLine.isEmptyOrWhitespace) { - startLine = doc.lineAt(startLine.lineNumber+1) + let startLine = null; + if (position.line == 0) { + startLine = doc.lineAt(position.line); + } else { + startLine = doc.lineAt(position.line-1); + while (!startLine.isEmptyOrWhitespace && startLine.lineNumber > 0) { + startLine = doc.lineAt(startLine.lineNumber-1) + } + if (startLine.isEmptyOrWhitespace) { + startLine = doc.lineAt(startLine.lineNumber+1) + } } + let endLine = doc.lineAt(position.line); let createMatch = startLine.text.match(/create\s+(or\s+replace\s+)?(\w+)\s+(\S+)/) if (createMatch) { while (!endLine.text.match("end " + createMatch[3] + ";") && endLine.lineNumber < doc.lineCount-1) {