forked from martin-pabst/SQL-IDE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemicolonAngel.ts
More file actions
70 lines (53 loc) · 2.36 KB
/
SemicolonAngel.ts
File metadata and controls
70 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as monaco from 'monaco-editor';
import { MainBase } from "../../main/MainBase.js";
import { TextPosition } from "../lexer/Token";
import { Module } from "./Module";
type SemicolonPosition = {
position: TextPosition;
module: Module;
firstSeenMs: number;
isThereAgain: boolean;
}
export class SemicolonAngel {
semicolonPositions: SemicolonPosition[] = [];
time: number;
constructor(private main: MainBase){
}
startRegistering(){
this.semicolonPositions.forEach(p => p.isThereAgain = false);
this.time = new Date().getTime();
}
register(position: TextPosition, module: Module){
let oldEvidence = this.semicolonPositions.find(p => p.position.line == position.line && p.position.column == position.column);
if(oldEvidence){
oldEvidence.isThereAgain = true;
} else {
this.semicolonPositions.push({position: position, firstSeenMs: this.time, isThereAgain: true, module: module});
}
}
healSemicolons(){
let time = new Date().getTime();
this.semicolonPositions = this.semicolonPositions.filter(p => p.isThereAgain);
let currentlyEditedModule = this.main.getCurrentlyEditedModule();
let cursorLine = this.main.getMonacoEditor().getPosition().lineNumber;
this.semicolonPositions.filter(p => time - p.firstSeenMs > 2000).forEach(p => {
let isCurrentModule = p.module.file.id != null && p.module.file.id == currentlyEditedModule.file.id;
let editOperations: monaco.editor.IIdentifiedSingleEditOperation[] = [
{
range: new monaco.Range(p.position.line, p.position.column, p.position.line, p.position.column),
text: ";",
forceMoveMarkers: true
}
]
if(isCurrentModule){
if(Math.abs(cursorLine - p.position.line) > 1){
let editor = this.main.getMonacoEditor();
const selection = editor.getSelection();
editor.executeEdits('Semicolon-Angel', editOperations);
editor.setSelection(selection);
this.semicolonPositions.splice(this.semicolonPositions.indexOf(p), 1);
}
}
});
}
}