mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
Merge pull request #2930 from JParisFerrer/vim_tab_switching
Add tab switching support to vim mode
This commit is contained in:
commit
9372eef691
@ -205,6 +205,32 @@ export function Root(props: IProps): React.ReactElement {
|
||||
save();
|
||||
props.router.toTerminal();
|
||||
});
|
||||
|
||||
// Setup "go to next tab" and "go to previous tab". This is a little more involved
|
||||
// since these aren't Ex commands (they run in normal mode, not after typing `:`)
|
||||
MonacoVim.VimMode.Vim.defineAction("nextTabs", function (_cm: any, args: {repeat?: number}, _vim: any) {
|
||||
const nTabs = args.repeat ?? 1;
|
||||
// Go to the next tab (to the right). Wraps around when at the rightmost tab
|
||||
const currIndex = currentTabIndex();
|
||||
if (currIndex !== undefined) {
|
||||
const nextIndex = (currIndex + nTabs) % openScripts.length;
|
||||
onTabClick(nextIndex);
|
||||
}
|
||||
});
|
||||
MonacoVim.VimMode.Vim.defineAction("prevTabs", function (_cm: any, args: {repeat?: number}, _vim: any) {
|
||||
const nTabs = args.repeat ?? 1;
|
||||
// Go to the previous tab (to the left). Wraps around when at the leftmost tab
|
||||
const currIndex = currentTabIndex();
|
||||
if (currIndex !== undefined) {
|
||||
let nextIndex = (currIndex - nTabs);
|
||||
while (nextIndex < 0) {
|
||||
nextIndex += openScripts.length;
|
||||
}
|
||||
onTabClick(nextIndex);
|
||||
}
|
||||
});
|
||||
MonacoVim.VimMode.Vim.mapCommand("gt", "action", "nextTabs", {}, {context: "normal"});
|
||||
MonacoVim.VimMode.Vim.mapCommand("gT", "action", "prevTabs", {}, {context: "normal"});
|
||||
editor.focus();
|
||||
});
|
||||
} catch { }
|
||||
@ -604,17 +630,27 @@ export function Root(props: IProps): React.ReactElement {
|
||||
openScripts = items;
|
||||
}
|
||||
|
||||
function onTabClick(index: number): void {
|
||||
function currentTabIndex(): number | undefined {
|
||||
if (currentScript !== null) {
|
||||
// Save currentScript to openScripts
|
||||
const curIndex = openScripts.findIndex(
|
||||
return openScripts.findIndex(
|
||||
(script) =>
|
||||
currentScript !== null &&
|
||||
script.fileName === currentScript.fileName &&
|
||||
script.hostname === currentScript.hostname,
|
||||
);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function onTabClick(index: number): void {
|
||||
if (currentScript !== null) {
|
||||
// Save currentScript to openScripts
|
||||
const curIndex = currentTabIndex();
|
||||
if (curIndex !== undefined) {
|
||||
openScripts[curIndex] = currentScript;
|
||||
}
|
||||
}
|
||||
|
||||
currentScript = { ...openScripts[index] };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user