Skip to content

Commit

Permalink
Add config to open navigated files in preview mode (default: false)
Browse files Browse the repository at this point in the history
Fixes #4.
  • Loading branch information
jtanx committed Oct 7, 2017
1 parent 54bd54e commit 54609c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the "ctagsx" extension will be documented in this file.
## [1.0.4] - 2017-10-07
### Added
- Added a new command to manually enter the tag to jump to via an input prompt (default: `Ctrl+alt+t`/`Cmd+alt+t`)
- Added a preference (`ctagsx.openAsPreview`) to open the navigated file in preview mode (default: `false`). This restores to default behaviour as observed pre VSCode 1.15.

## [1.0.3] - 2017-05-13
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To search for a tag, press `Ctrl+t`/`Cmd+t`. To jump back to where you searched
* Searches tags files relative to the source file being edited

## Extension Settings
None at the moment
* `ctagsx.openAsPreview`: Controls if the navigated file will be opened in preview mode (default: `false`)

## Known Issues
Please report any issues to https://github.com/jtanx/ctagsx/issues
Expand Down
45 changes: 21 additions & 24 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,7 @@ function jumpBack(context) {
return context.workspaceState.update('CTAGSX_JUMP_STACK', stack).then(() => {
const uri = vscode.Uri.parse(position.uri)
const sel = new vscode.Selection(position.lineNumber, position.charPos, position.lineNumber, position.charPos)
return vscode.workspace.openTextDocument(uri).then(doc => {
const editor = vscode.window.activeTextEditor
const viewColumn = editor ? editor.viewColumn : vscode.ViewColumn.One
return vscode.window.showTextDocument(doc, viewColumn).then(editor => {
editor.selection = sel
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter)
})
})
return openAndReveal(context, vscode.window.activeTextEditor, uri, sel)
})
}
}
Expand Down Expand Up @@ -218,35 +211,39 @@ function getFileLineNumber(editor) {
return Promise.resolve()
}

function openAndReveal(context, editor, document, sel, doSaveState) {
if (doSaveState) {
return saveState(context, editor).then(() => openAndReveal(context, editor, document, sel))
}
return vscode.workspace.openTextDocument(document).then(doc => {
const viewColumn = editor ? editor.viewColumn : vscode.ViewColumn.One
const preview = vscode.workspace.getConfiguration('ctagsx').get('openAsPreview')

return vscode.window.showTextDocument(doc, {preview, viewColumn}).then(editor => {
if (sel) {
editor.selection = sel
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter)
}
})
})
}

function revealCTags(context, editor, entry) {
if (!entry) {
return
}

const openAndReveal = (sel) => {
return saveState(context, editor).then(() => {
return vscode.workspace.openTextDocument(entry.file)
}).then(doc => {
return vscode.window.showTextDocument(doc, editor.viewColumn).then(editor => {
if (sel) {
editor.selection = sel
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter)
}
})
})
}

if (entry.address.lineNumber === 0) {
return getLineNumber(entry).then(sel => {
return openAndReveal(sel)
return openAndReveal(context, editor, entry.file, sel, true)
})
} else if (entry.kind === 'F') {
return getFileLineNumber(editor).then(sel => {
return openAndReveal(sel)
return openAndReveal(context, editor, entry.file, sel, true)
})
} else {
const lineNumber = Math.max(0, entry.address.lineNumber - 1)
const sel = new vscode.Selection(lineNumber, 0, lineNumber, 0)
return openAndReveal(sel)
return openAndReveal(context, editor, entry.file, sel, true)
}
}
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
],
"main": "./extension",
"contributes": {
"configuration": {
"type": "object",
"title": "ctagsx configuration",
"properties": {
"ctagsx.openAsPreview": {
"type": "boolean",
"default": false,
"description": "Open navigated to files in preview mode"
}
}
},
"commands": [
{
"command": "extension.findCTags",
Expand Down

0 comments on commit 54609c3

Please sign in to comment.