mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
Bookmarks mainview keybindings (#462)
* first keybind for bookmarks * finished adding bookmark keybindings * removing logs * fix up/down directions
This commit is contained in:
parent
bfafb9e490
commit
61c9d21014
@ -22,6 +22,59 @@ type BookmarkProps = {
|
|||||||
bookmark: BookmarkType;
|
bookmark: BookmarkType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BookmarkKeybindings extends React.Component<{}, {}> {
|
||||||
|
@boundMethod
|
||||||
|
componentDidMount(): void {
|
||||||
|
let keybindManager = GlobalModel.keybindManager;
|
||||||
|
let bookmarksModel = GlobalModel.bookmarksModel;
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:cancel", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserClose();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:deleteItem", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserDelete();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:selectAbove", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserNavigate(-1);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:selectBelow", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserNavigate(1);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:selectPageAbove", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserNavigate(-10);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:selectPageBelow", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserNavigate(10);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "generic:confirm", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserConfirm();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "bookmarks:edit", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserEdit();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
keybindManager.registerKeybinding("mainview", "bookmarks", "bookmarks:copy", (waveEvent) => {
|
||||||
|
bookmarksModel.handleUserCopy();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@boundMethod
|
||||||
|
componentWillUnmount() {
|
||||||
|
GlobalModel.keybindManager.unregisterDomain("bookmarks");
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@mobxReact.observer
|
@mobxReact.observer
|
||||||
class Bookmark extends React.Component<BookmarkProps, {}> {
|
class Bookmark extends React.Component<BookmarkProps, {}> {
|
||||||
@boundMethod
|
@boundMethod
|
||||||
@ -194,6 +247,9 @@ class BookmarksView extends React.Component<{}, {}> {
|
|||||||
let bookmark: BookmarkType = null;
|
let bookmark: BookmarkType = null;
|
||||||
return (
|
return (
|
||||||
<MainView className="bookmarks-view" title="Bookmarks" onClose={this.handleClose}>
|
<MainView className="bookmarks-view" title="Bookmarks" onClose={this.handleClose}>
|
||||||
|
<If condition={!isHidden}>
|
||||||
|
<BookmarkKeybindings></BookmarkKeybindings>
|
||||||
|
</If>
|
||||||
<div className="bookmarks-list">
|
<div className="bookmarks-list">
|
||||||
<For index="idx" each="bookmark" of={bookmarks}>
|
<For index="idx" each="bookmark" of={bookmarks}>
|
||||||
<Bookmark key={bookmark.bookmarkid} bookmark={bookmark} />
|
<Bookmark key={bookmark.bookmarkid} bookmark={bookmark} />
|
||||||
|
@ -205,80 +205,76 @@ class BookmarksModel {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDocKeyDown(e: any): void {
|
handleUserClose() {
|
||||||
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
|
if (this.editingBookmark.get() != null) {
|
||||||
if (checkKeyPressed(waveEvent, "Escape")) {
|
this.cancelEdit();
|
||||||
e.preventDefault();
|
|
||||||
if (this.editingBookmark.get() != null) {
|
|
||||||
this.cancelEdit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.closeView();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.closeView();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUserDelete() {
|
||||||
if (this.editingBookmark.get() != null) {
|
if (this.editingBookmark.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkKeyPressed(waveEvent, "Backspace") || checkKeyPressed(waveEvent, "Delete")) {
|
if (this.activeBookmark.get() == null) {
|
||||||
if (this.activeBookmark.get() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
this.handleDeleteBookmark(this.activeBookmark.get());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.handleDeleteBookmark(this.activeBookmark.get());
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
handleUserNavigate(amt: number) {
|
||||||
checkKeyPressed(waveEvent, "ArrowUp") ||
|
if (this.editingBookmark.get() != null) {
|
||||||
checkKeyPressed(waveEvent, "ArrowDown") ||
|
|
||||||
checkKeyPressed(waveEvent, "PageUp") ||
|
|
||||||
checkKeyPressed(waveEvent, "PageDown")
|
|
||||||
) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (this.bookmarks.length == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let newPos = 0; // if active is null, then newPos will be 0 (select the first)
|
|
||||||
if (this.activeBookmark.get() != null) {
|
|
||||||
let amtMap = { ArrowUp: -1, ArrowDown: 1, PageUp: -10, PageDown: 10 };
|
|
||||||
let amt = amtMap[e.code];
|
|
||||||
let curIdx = this.getBookmarkPos(this.activeBookmark.get());
|
|
||||||
newPos = curIdx + amt;
|
|
||||||
if (newPos < 0) {
|
|
||||||
newPos = 0;
|
|
||||||
}
|
|
||||||
if (newPos >= this.bookmarks.length) {
|
|
||||||
newPos = this.bookmarks.length - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let bm = this.bookmarks[newPos];
|
|
||||||
mobx.action(() => {
|
|
||||||
this.activeBookmark.set(bm.bookmarkid);
|
|
||||||
})();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkKeyPressed(waveEvent, "Enter")) {
|
if (this.bookmarks.length == 0) {
|
||||||
if (this.activeBookmark.get() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.useBookmark(this.activeBookmark.get());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkKeyPressed(waveEvent, "e")) {
|
let newPos = 0; // if active is null, then newPos will be 0 (select the first)
|
||||||
if (this.activeBookmark.get() == null) {
|
if (this.activeBookmark.get() != null) {
|
||||||
return;
|
let curIdx = this.getBookmarkPos(this.activeBookmark.get());
|
||||||
|
newPos = curIdx + amt;
|
||||||
|
if (newPos < 0) {
|
||||||
|
newPos = 0;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
if (newPos >= this.bookmarks.length) {
|
||||||
this.handleEditBookmark(this.activeBookmark.get());
|
newPos = this.bookmarks.length - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let bm = this.bookmarks[newPos];
|
||||||
|
mobx.action(() => {
|
||||||
|
this.activeBookmark.set(bm.bookmarkid);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUserConfirm() {
|
||||||
|
if (this.editingBookmark.get() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkKeyPressed(waveEvent, "c")) {
|
if (this.activeBookmark.get() == null) {
|
||||||
if (this.activeBookmark.get() == null) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
this.handleCopyBookmark(this.activeBookmark.get());
|
|
||||||
}
|
}
|
||||||
|
this.useBookmark(this.activeBookmark.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUserEdit() {
|
||||||
|
if (this.editingBookmark.get() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.activeBookmark.get() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.handleEditBookmark(this.activeBookmark.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUserCopy() {
|
||||||
|
if (this.editingBookmark.get() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.activeBookmark.get() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.handleCopyBookmark(this.activeBookmark.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,9 +491,7 @@ class Model {
|
|||||||
this.modalsModel.popModal();
|
this.modalsModel.popModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.activeMainView.get() == "bookmarks") {
|
this.keybindManager.processKeyEvent(e, waveEvent);
|
||||||
this.bookmarksModel.handleDocKeyDown(e);
|
|
||||||
}
|
|
||||||
if (this.activeMainView.get() == "history") {
|
if (this.activeMainView.get() == "history") {
|
||||||
this.historyViewModel.handleDocKeyDown(e);
|
this.historyViewModel.handleDocKeyDown(e);
|
||||||
}
|
}
|
||||||
@ -535,7 +533,6 @@ class Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.keybindManager.processKeyEvent(e, waveEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteActiveLine(): boolean {
|
deleteActiveLine(): boolean {
|
||||||
|
@ -38,7 +38,7 @@ type Keybind = {
|
|||||||
commandStr: string;
|
commandStr: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const KeybindLevels = ["system", "modal", "app", "pane", "plugin"];
|
const KeybindLevels = ["system", "modal", "app", "mainview", "pane", "plugin"];
|
||||||
|
|
||||||
class KeybindManager {
|
class KeybindManager {
|
||||||
domainCallbacks: Map<string, KeybindCallback>;
|
domainCallbacks: Map<string, KeybindCallback>;
|
||||||
@ -159,8 +159,6 @@ class KeybindManager {
|
|||||||
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
||||||
if (curDomainCallback != null) {
|
if (curDomainCallback != null) {
|
||||||
shouldReturn = curDomainCallback(event);
|
shouldReturn = curDomainCallback(event);
|
||||||
} else {
|
|
||||||
console.log("domain callback for ", curKeybind.domain, " is null. This should never happen");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shouldRunCommand) {
|
if (shouldRunCommand) {
|
||||||
|
Loading…
Reference in New Issue
Block a user