My problem is that I have a WEB application and I use typescript with angularjs 4
I need to do keyEvent or something else that every time I print small comments ("//") anywhere, I need them to be replaced with large comments ('/ * XXX * /') and the cursor ( marked with XXX)
I went so far as to be able to read a line from the editor and edit comments, but there is a problem with replacing the line, and I don't know why, because there is no error on the console.
Here is the code:
@HostListener( 'window:keydown', ['$event'] ) keyboardInput( e: any ) {
if ( e.key === '/' && this.globalService.mode === 'EDIT' ) {
this.backslashCounter++;
const column = this.globalService.editor.getEditor().session.selection.selectionAnchor.column;
const row = this.globalService.editor.getEditor().session.selection.selectionAnchor.row;
this.currentLine = '' + this.globalService.editor.getEditor().session.selection.doc.getLines( row, row );
if ( this.backslashCounter === 2 ) {
if ( this.currentLine.substr( column - 1, 1 ) === '/' ) {
this.backslashCounter = 0;
currentLine = this.removeSmallCommentsWithBigOnes(currentLine);
const editor = this.globalService.editor.getEditor();
const range = this.globalService.editor.getEditor().session.selection.getRange();
range.start.column = 0;
range.end.column = currentLine.length + 5;
editor.replace( range, currentLine );
this.globalService.editor.getEditor().session.selection.moveTo( row, column + 2 );
} else {
this.backslashCounter--;
}
}
}
}
So, the code performs the following actions: First IF, checks if the "/" key is pressed
The second IF, checks if there are 2 of them,
IF, , , , , 1
, JAVASCRIPT, TYPESCRIPT, , .
, , , , , , , .
.