-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
161 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as vscode from 'vscode'; | ||
import { previousActiveEditor, updatePreviousActiveEditor } from './editorContext'; | ||
import { activeQP } from './quickpickContext'; | ||
import { AllQPItemVariants, QPItemQuery } from '../types'; | ||
import { getConfig } from '../utils/getConfig'; | ||
import { highlightLineDecorationType } from '../utils/decorationType'; | ||
|
||
export function closePreviewEditor() { | ||
if(previousActiveEditor) { | ||
vscode.commands.executeCommand('workbench.action.closeActiveEditor'); | ||
updatePreviousActiveEditor(undefined); // prevent focus onDidHide | ||
} | ||
} | ||
|
||
// Open the current qp selected item in a horizontal split | ||
export const openInHorizontalSplit = () => { | ||
if(!activeQP) { | ||
return; | ||
} | ||
|
||
// grab the current selected item | ||
const currentItem = activeQP.activeItems[0] as QPItemQuery; | ||
|
||
if (!currentItem?.data) { | ||
return; | ||
} | ||
|
||
const options: vscode.TextDocumentShowOptions = { | ||
viewColumn: vscode.ViewColumn.Beside, | ||
}; | ||
|
||
closePreviewEditor(); | ||
|
||
const { filePath, linePos, colPos } = currentItem.data; | ||
vscode.workspace.openTextDocument(filePath).then((document) => { | ||
vscode.window.showTextDocument(document, options).then((editor) => { | ||
// set cursor & view position | ||
const position = new vscode.Position(linePos, colPos); | ||
editor.revealRange(new vscode.Range(position, position)); | ||
activeQP?.dispose(); | ||
}); | ||
}); | ||
}; | ||
|
||
// Open the native VSCode search with the provided query and enable regex | ||
export function openNativeVscodeSearch(query: string, qp: vscode.QuickPick<AllQPItemVariants>) { | ||
// remove the config suffix from the query | ||
const trimmedQuery = query.slice( | ||
0, | ||
query.indexOf(getConfig().gotoNativeSearchSuffix) | ||
); | ||
|
||
vscode.commands.executeCommand('workbench.action.findInFiles', { | ||
query: trimmedQuery, | ||
isRegex: true, | ||
isCaseSensitive: false, | ||
matchWholeWord: false, | ||
triggerSearch: true, | ||
}); | ||
|
||
// close extension down | ||
qp.hide(); | ||
} | ||
|
||
export function setCursorPosition(editor: vscode.TextEditor, linePos: number, colPos: number) { | ||
const selection = new vscode.Selection(0, 0, 0, 0); | ||
editor.selection = selection; | ||
|
||
const lineNumber = Math.max(linePos ? linePos - 1 : 0, 0); | ||
const charNumber = Math.max(colPos ? colPos - 1 : 0, 0); | ||
|
||
editor | ||
.edit(editBuilder => { | ||
editBuilder.insert(selection.active, ''); | ||
}) | ||
.then(() => { | ||
const newPosition = new vscode.Position(lineNumber, charNumber); | ||
const range = editor.document.lineAt(newPosition).range; | ||
editor.selection = new vscode.Selection(newPosition, newPosition); | ||
editor.revealRange(range, vscode.TextEditorRevealType.InCenter); | ||
highlightLineDecorationType().set(editor); | ||
}); | ||
} |
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,8 @@ | ||
// lib/editorContext.ts | ||
import * as vscode from 'vscode'; | ||
|
||
export let previousActiveEditor: vscode.TextEditor | undefined; | ||
|
||
export function updatePreviousActiveEditor(editor: vscode.TextEditor | undefined) { | ||
previousActiveEditor = editor; | ||
} |
Oops, something went wrong.