-
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
6 changed files
with
130 additions
and
43 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
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,45 @@ | ||
import * as vscode from 'vscode'; | ||
import { getConfig } from './getConfig'; | ||
|
||
/** | ||
* Util to create a decoration type (for highlighting) for when 'peeking' at a file | ||
*/ | ||
export function highlightDecorationType() { | ||
const { | ||
peekBorderColor: borderColor, | ||
peekBorderWidth: borderWidth, | ||
peekBorderStyle: borderStyle, | ||
} = getConfig(); | ||
|
||
function get() { | ||
const decorationType = vscode.window.createTextEditorDecorationType({ | ||
isWholeLine: true, | ||
borderWidth: `0 0 ${borderWidth} 0`, | ||
borderStyle: `${borderStyle}`, | ||
borderColor, | ||
}); | ||
|
||
return decorationType; | ||
} | ||
const decorationType = get(); | ||
|
||
function set(editor: vscode.TextEditor) { | ||
const currentPosition = editor.selection.active; | ||
const newDecoration = { | ||
range: new vscode.Range(currentPosition, currentPosition), | ||
}; | ||
editor.setDecorations(decorationType, [newDecoration]); | ||
} | ||
|
||
function remove() { | ||
if (decorationType) { | ||
vscode.window.activeTextEditor?.setDecorations(decorationType, []); | ||
decorationType.dispose(); | ||
} | ||
} | ||
|
||
return { | ||
set, | ||
remove, | ||
}; | ||
} |
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,38 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
// CONFIG: this should match the contribution in package.json | ||
type ConfigItems = | ||
| 'rgOptions' | ||
| 'addSrcPaths' | ||
| 'rgGlobExcludes' | ||
| 'startFolderDisplayDepth' | ||
| 'endFolderDisplayDepth' | ||
| 'enableGotoNativeSearch' | ||
| 'gotoNativeSearchSuffix' | ||
| 'peekBorderColor' | ||
| 'peekBorderWidth' | ||
| 'peekBorderStyle'; | ||
|
||
export function getConfig() { | ||
const vsConfig = vscode.workspace.getConfiguration('periscope'); | ||
|
||
return { | ||
rgOptions: vsConfig.get<string[]>('rgOptions', [ | ||
'--smart-case', | ||
'--sortr path', | ||
]), | ||
addSrcPaths: vsConfig.get<string[]>('addSrcPaths', []), | ||
rgGlobExcludes: vsConfig.get<string[]>('rgGlobExcludes', []), | ||
startFolderDisplayDepth: vsConfig.get<number>('startFolderDisplayDepth', 1), | ||
endFolderDisplayDepth: vsConfig.get<number>('endFolderDisplayDepth', 4), | ||
enableGotoNativeSearch: vsConfig.get<boolean>( | ||
'enableGotoNativeSearch', | ||
true | ||
), | ||
gotoNativeSearchSuffix: | ||
vsConfig.get<string>('gotoNativeSearchSuffix', '>>') || '>>', | ||
peekBorderColor: vsConfig.get<string>('peekBorderColor', 'rgb(0,255,246)'), | ||
peekBorderWidth: vsConfig.get<string>('peekBorderWidth', '2px'), | ||
peekBorderStyle: vsConfig.get<string>('peekBorderStyle', 'solid'), | ||
} as const satisfies { [key in ConfigItems]: any }; | ||
} |
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,10 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function getSelectedText() { | ||
let selectedText = ''; | ||
const editor = vscode.window.activeTextEditor; | ||
if (editor) { | ||
selectedText = editor.document.getText(editor.selection); | ||
} | ||
return selectedText; | ||
} |