-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from ejgallego/move_backwards_forward
[vscode] Add simple commands to move backwards / forward in a proof.
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Edition facilities for Coq files | ||
import { TextEditor, Position, Range, Selection } from "vscode"; | ||
|
||
export function sentenceBack(editor: TextEditor) { | ||
// Slice from the beginning of the document | ||
let cursor = editor.selection.active; | ||
let range = new Range(editor.document.positionAt(0), cursor); | ||
let text = editor.document.getText(range); | ||
|
||
// what a hack | ||
let regres = text.match(/\.\s+/g); | ||
if (regres) { | ||
let match = regres.at(-2) || ""; | ||
var index = 0; | ||
if (match == regres.at(-1) || "") { | ||
let idx = text.lastIndexOf(match); | ||
index = text.lastIndexOf(match, idx - 1) + match.length; | ||
} else { | ||
index = text.lastIndexOf(match) + match.length; | ||
} | ||
let newCursor = editor.document.positionAt(index); | ||
editor.selection = new Selection(newCursor, newCursor); | ||
} | ||
} | ||
|
||
export function sentenceNext(editor: TextEditor) { | ||
// Slice to the end of the document | ||
let cursor = editor.selection.active; | ||
let lastLine = editor.document.lineCount - 1; | ||
let lastPos = editor.document.lineAt(lastLine).range.end; | ||
let range = new Range(cursor, lastPos); | ||
let text = editor.document.getText(range); | ||
|
||
// get the offset of the first match | ||
let regres = text.match(/\.\s+/); | ||
if (regres) { | ||
regres; | ||
let match: any = regres[0]; | ||
let index = regres.index + match.length; | ||
let newCursor = editor.document.positionAt( | ||
editor.document.offsetAt(cursor) + index | ||
); | ||
editor.selection = new Selection(newCursor, newCursor); | ||
} | ||
} |