-
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.
also removed activeQP requirement and utilises setCursorPos as well
- Loading branch information
Showing
8 changed files
with
446 additions
and
444 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import * as vscode from 'vscode'; | ||
import { periscope } from './lib/periscope'; | ||
import { openInHorizontalSplit } from './lib/editorActions'; | ||
import { PERISCOPE } from './lib/periscope'; | ||
import { log } from './utils/log'; | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
console.log('<<PERISCOPE>> is now active.'); | ||
log('activate'); | ||
|
||
const periscopeQpCmd = vscode.commands.registerCommand('periscope.search', | ||
() => periscope().register() | ||
() => PERISCOPE.search() | ||
); | ||
|
||
const periscopeSplitCmd = vscode.commands.registerCommand("periscope.openInHorizontalSplit", () => { | ||
openInHorizontalSplit(); | ||
}); | ||
const periscopeSplitCmd = vscode.commands.registerCommand("periscope.openInHorizontalSplit", | ||
() => PERISCOPE.openInHorizontalSplit() | ||
); | ||
|
||
context.subscriptions.push(periscopeQpCmd, periscopeSplitCmd); | ||
} |
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,53 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { log } from "../utils/log"; | ||
import { updatePreviousActiveEditor } from "./editorContext"; | ||
import { checkKillProcess } from "./ripgrep"; | ||
import { context as cx } from './context'; | ||
import { QPItemQuery } from '../types'; | ||
import { closePreviewEditor, setCursorPosition } from './editorActions'; | ||
|
||
export function accept(item?: QPItemQuery) { | ||
checkKillProcess(); | ||
|
||
const currentItem = item ? item : cx.qp.selectedItems[0] as QPItemQuery; | ||
if (!currentItem?.data) { | ||
return; | ||
} | ||
|
||
const { filePath, linePos, colPos } = currentItem.data; | ||
vscode.workspace.openTextDocument(path.resolve(filePath)).then(document => { | ||
const options: vscode.TextDocumentShowOptions = {}; | ||
|
||
if(item) { // horizontal split | ||
options.viewColumn = vscode.ViewColumn.Beside; | ||
closePreviewEditor(); | ||
} | ||
|
||
vscode.window.showTextDocument(document, options).then(editor => { | ||
setCursorPosition(editor, linePos, colPos); | ||
cx.qp.dispose(); | ||
}); | ||
}); | ||
} | ||
|
||
export function finished() { | ||
checkKillProcess(); | ||
cx.highlightDecoration.remove(); | ||
setActiveContext(false); | ||
disposeAll(); | ||
updatePreviousActiveEditor(undefined); | ||
log('finished'); | ||
} | ||
|
||
// create vscode context for the extension for targeted keybindings | ||
export function setActiveContext(flag: boolean) { | ||
log(`setContext ${flag}`); | ||
vscode.commands.executeCommand('setContext', 'periscopeActive', flag); | ||
} | ||
|
||
function disposeAll() { | ||
cx.disposables.general.forEach(d => d.dispose()); | ||
cx.disposables.rgMenuActions.forEach(d => d.dispose()); | ||
cx.disposables.query.forEach(d => d.dispose()); | ||
} |
Oops, something went wrong.