vscode#TextEditorRevealType TypeScript Examples

The following examples show how to use vscode#TextEditorRevealType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeLinkFeature.ts    From vscode-drawio with GNU General Public License v3.0 6 votes vote down vote up
private async revealSelection(
		pos: DeserializedCodePosition
	): Promise<void> {
		if (pos.range) {
			const d = await workspace.openTextDocument(pos.uri);
			const e = await window.showTextDocument(d, {
				viewColumn: ViewColumn.One,
				preserveFocus: true,
			});
			e.revealRange(pos.range, TextEditorRevealType.Default);

			const highlightDecorationType =
				window.createTextEditorDecorationType({
					backgroundColor: new ThemeColor(
						"editor.stackFrameHighlightBackground"
					),
				});

			if (this.lastDecorationType) {
				e.setDecorations(this.lastDecorationType, []);
			}
			this.lastDecorationType = highlightDecorationType;

			e.setDecorations(highlightDecorationType, [pos.range]);
			wait(1000).then(() => {
				e.setDecorations(highlightDecorationType, []);
			});
		} else {
			await commands.executeCommand("vscode.open", pos.uri, {
				viewColumn: ViewColumn.One,
				preserveFocus: true,
			});
		}
	}
Example #2
Source File: infoview.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
private async revealEditorSelection(uri: Uri, selection?: Range) {
        let editor: TextEditor | undefined;
        for (const e of window.visibleTextEditors) {
            if (e.document.uri.toString() === uri.toString()) {
                editor = e;
                break;
            }
        }
        if (!editor) {
            const c = window.activeTextEditor ? window.activeTextEditor.viewColumn : ViewColumn.One;
            editor = await window.showTextDocument(uri, { viewColumn: c, preserveFocus: false });
        }
        if (selection !== undefined) {
            editor.revealRange(selection, TextEditorRevealType.InCenterIfOutsideViewport);
            editor.selection = new Selection(selection.start, selection.end);
            // ensure the text document has the keyboard focus.
            await window.showTextDocument(editor.document, { viewColumn: editor.viewColumn, preserveFocus: false });
        }
    }
Example #3
Source File: documentActions.ts    From vscode-todo-md with MIT License 6 votes vote down vote up
/**
 * Reveal the line/task in the file.
 *
 * Move cursor, reveal range, highlight the line for a moment
 */
export async function revealTask(lineNumber: number, document?: TextDocument) {
	const documentToReveal = document ?? await getActiveOrDefaultDocument();
	const editor = await window.showTextDocument(documentToReveal);
	const range = new Range(lineNumber, 0, lineNumber, 0);
	editor.selection = new Selection(range.start, range.end);
	editor.revealRange(range, TextEditorRevealType.Default);
	// Highlight for a short time revealed range
	const lineHighlightDecorationType = window.createTextEditorDecorationType({
		backgroundColor: '#ffa30468',
		isWholeLine: true,
	});
	editor.setDecorations(lineHighlightDecorationType, [range]);
	setTimeout(() => {
		editor.setDecorations(lineHighlightDecorationType, []);
	}, 700);
}
Example #4
Source File: extension.ts    From vscode-plugin-swimming with MIT License 5 votes vote down vote up
function rewriteCode(
    textEditor: TextEditor,
    edit: TextEditorEdit,
    _args: any[]
) {
    if(isWritingCodeMap.get(textEditor.document.fileName)) {
        return window.showInformationMessage('rewriteCode already in progress')
    }
    isWritingCodeMap.set(textEditor.document.fileName,true)
    isWriteCodePauseMap.set(textEditor.document.fileName,false)
    const { start, end } = textEditor.selection;
    let i = 0;
    let selectionRange = new Range(start, end);

    if (selectionRange.isEmpty) {
        const end = new Position(textEditor.document.lineCount + 1, 0);
        selectionRange = new Range(new Position(0, 0), end);
    }

    const beforeText = textEditor.document.getText(selectionRange);

    edit.delete(selectionRange);
    let { line, character } = textEditor.selection.start;
    const recycleWrite = function(inputTimeout: NodeJS.Timeout) {
        isWritingCodeMap.set(textEditor.document.fileName,false)
        clearTimeout(inputTimeout);
    }
    const runWrite = function() {
        const inputTimeout: NodeJS.Timeout = setTimeout(() => {
            if(isWriteCodePauseMap.get(textEditor.document.fileName)) {
                return textEditor.edit((_editBuilder) => {})
                .then((_value:boolean)=>{
                    return runWrite();
                },(reason)=>{
                    recycleWrite(inputTimeout)
                    throw new Error(reason);
                })
            }
            if (i >= beforeText.length || textEditor.document.isClosed) {
                return recycleWrite(inputTimeout)
            }
            const nowPosition = new Position(line, character);
            textEditor.edit((editBuilder) => {
                textEditor.revealRange(
                    new Range(nowPosition, nowPosition),
                    TextEditorRevealType.InCenter
                )
                if (beforeText.startsWith('\r\n', i)) {
                    character = 0;
                    line++
                    editBuilder.insert(nowPosition, '\r\n');
                    return i+=2;
                }
                if (beforeText.startsWith('\n', i)) {
                    character = 0;
                    line++
                    editBuilder.insert(nowPosition, '\n');
                    return i+=1;
                }
                editBuilder.insert(nowPosition, beforeText[i++]);
                character++;
            }).then((_value:boolean)=>{
                return runWrite();
            },(reason)=>{
                recycleWrite(inputTimeout)
                throw new Error(reason);
            })
        }, getReWriteSpeed());
    }
    runWrite();
    
}