mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds move-next/previous-entity commands (#92)
This commit is contained in:
parent
e1de039a4a
commit
5a6a70a981
@ -67,6 +67,9 @@ Essential commands
|
||||
RET visit thing at point
|
||||
shift+4 show git process view
|
||||
q exit / close magit view
|
||||
|
||||
ctrl+j Move cursor to next entity
|
||||
ctrl+k Move cursor to previous entity
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
10
package.json
10
package.json
@ -628,6 +628,16 @@
|
||||
"key": "q",
|
||||
"when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
|
||||
},
|
||||
{
|
||||
"command": "magit.move-next-entity",
|
||||
"key": "ctrl+j",
|
||||
"when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
|
||||
},
|
||||
{
|
||||
"command": "magit.move-previous-entity",
|
||||
"key": "ctrl+k",
|
||||
"when": "editorTextFocus && editorLangId == 'magit' && vim.mode =~ /^(?!SearchInProgressMode|CommandlineInProgress).*$/"
|
||||
},
|
||||
{
|
||||
"command": "magit.save-and-close-editor",
|
||||
"key": "ctrl+c ctrl+c",
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { commands, TextEditor, Range } from 'vscode';
|
||||
import { commands, TextEditor, Range, window, Selection } from 'vscode';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { DocumentView } from '../views/general/documentView';
|
||||
import { View } from '../views/general/view';
|
||||
|
||||
export async function saveClose() {
|
||||
await commands.executeCommand('workbench.action.files.save');
|
||||
@ -15,4 +18,58 @@ export async function clearSaveClose(editor: TextEditor) {
|
||||
// workaround for issue #11
|
||||
export async function quitMagitView() {
|
||||
return commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
}
|
||||
|
||||
|
||||
const subViewDepthSearchFlatten = (view: View, depth: number = 0): View[] => {
|
||||
if (view.folded || depth >= 3) {
|
||||
return [];
|
||||
}
|
||||
// .filter(v => v.isFoldable)
|
||||
return view.subViews.flatMap(v => [v, ...subViewDepthSearchFlatten(v, depth + 1)]);
|
||||
};
|
||||
|
||||
export async function moveToNextEntity(repo: MagitRepository, view: DocumentView) {
|
||||
moveToEntity(view, 'next');
|
||||
}
|
||||
|
||||
export async function moveToPreviousEntity(repo: MagitRepository, view: DocumentView) {
|
||||
moveToEntity(view, 'previous');
|
||||
}
|
||||
|
||||
function moveToEntity(view: View, direction: 'next' | 'previous') {
|
||||
const selectedView = view.click(window.activeTextEditor!.selection.active);
|
||||
|
||||
if (selectedView) {
|
||||
|
||||
let foldableViews = [view, ...subViewDepthSearchFlatten(view)];
|
||||
|
||||
if (direction === 'previous') {
|
||||
foldableViews = foldableViews.reverse();
|
||||
}
|
||||
|
||||
let nextviewIndex = foldableViews.indexOf(selectedView);
|
||||
|
||||
if (nextviewIndex !== -1) {
|
||||
|
||||
let nextView = foldableViews.slice(nextviewIndex + 1).find(v => v.isFoldable);
|
||||
|
||||
if (nextView) {
|
||||
let nextLocation = nextView.range.start;
|
||||
window.activeTextEditor!.selection = new Selection(nextLocation, nextLocation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid standing still and getting stuck
|
||||
if (direction === 'next') {
|
||||
let newPos = selectedView.range.end.with({ line: selectedView.range.end.line });
|
||||
window.activeTextEditor!.selection = new Selection(newPos, newPos);
|
||||
} else if (direction === 'previous') {
|
||||
if (selectedView.range.start.line > 0) {
|
||||
let newPos = selectedView.range.start.with({ line: selectedView.range.start.line - 1 });
|
||||
window.activeTextEditor!.selection = new Selection(newPos, newPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import { magitVisitAtPoint } from './commands/visitAtPointCommands';
|
||||
import { MagitRepository } from './models/magitRepository';
|
||||
import { magitCommit } from './commands/commitCommands';
|
||||
import { magitStage, magitStageAll, magitUnstageAll, magitUnstage, stageFile, unstageFile } from './commands/stagingCommands';
|
||||
import { saveClose, clearSaveClose, quitMagitView } from './commands/macros';
|
||||
import { saveClose, clearSaveClose, quitMagitView, moveToPreviousEntity, moveToNextEntity } from './commands/macros';
|
||||
import HighlightProvider from './providers/highlightProvider';
|
||||
import SemanticTokensProvider from './providers/semanticTokensProvider';
|
||||
import { CommandPrimer } from './commands/commandPrimer';
|
||||
@ -144,6 +144,10 @@ export function activate(context: ExtensionContext) {
|
||||
}, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.quit', quitMagitView));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.move-next-entity', CommandPrimer.primeRepoAndView(moveToNextEntity, false)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.move-previous-entity', CommandPrimer.primeRepoAndView(moveToPreviousEntity, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.save-and-close-editor', saveClose));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.clear-and-abort-editor', clearSaveClose));
|
||||
}
|
||||
|
@ -207,7 +207,6 @@ export default class MagitUtils {
|
||||
|
||||
const _inputBox = window.createInputBox();
|
||||
_inputBox.validationMessage = renderedPrompt;
|
||||
_inputBox.show();
|
||||
|
||||
let changeListener = _inputBox.onDidChangeValue(e => {
|
||||
if (e.toLowerCase().includes('y')) {
|
||||
@ -228,6 +227,8 @@ export default class MagitUtils {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
_inputBox.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
import { DocumentView } from './general/documentView';
|
||||
import { Uri } from 'vscode';
|
||||
import * as Constants from '../common/constants';
|
||||
import { TextView } from './general/textView';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
|
||||
export class DispatchView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'dispatch.magit';
|
||||
needsUpdate = false;
|
||||
|
||||
constructor(public uri: Uri) {
|
||||
super(uri);
|
||||
|
||||
this.addSubview(new TextView(`Popup and dwim commands
|
||||
A Cherry-pick b Branch c Commit
|
||||
d Diff f Fetch F Pull
|
||||
i Ignore l Log m Merge
|
||||
M Remote P Push r Rebase
|
||||
t Tag V Revert X Reset
|
||||
y Show Refs z Stash ! Run % Worktree`));
|
||||
}
|
||||
|
||||
public update(state: MagitRepository): void { }
|
||||
|
||||
static encodeLocation(repository: MagitRepository): Uri {
|
||||
return Uri.parse(`${Constants.MagitUriScheme}:${DispatchView.UriPath}?${repository.uri.fsPath}`);
|
||||
}
|
||||
}
|
@ -83,6 +83,9 @@ Essential commands
|
||||
${HelpView.joinTexts(9, [c['magit.toggle-fold'], 'toggle section at point'])}
|
||||
${HelpView.joinTexts(9, [c['magit.visit-at-point'], 'visit thing at point'])}
|
||||
${HelpView.joinTexts(9, [c['magit.process-log'], 'show git process view'])}
|
||||
${HelpView.joinTexts(9, [c['magit.quit'], 'exit / close magit view'])}`;
|
||||
${HelpView.joinTexts(9, [c['magit.quit'], 'exit / close magit view'])}
|
||||
|
||||
${HelpView.joinTexts(9, [c['magit.move-next-entity'], 'Move cursor to next entity'])}
|
||||
${HelpView.joinTexts(9, [c['magit.move-previous-entity'], 'Move cursor to previous entity'])}`;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user