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;
|
||||
};
|
||||
|
||||
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
|
||||
class Bookmark extends React.Component<BookmarkProps, {}> {
|
||||
@boundMethod
|
||||
@ -194,6 +247,9 @@ class BookmarksView extends React.Component<{}, {}> {
|
||||
let bookmark: BookmarkType = null;
|
||||
return (
|
||||
<MainView className="bookmarks-view" title="Bookmarks" onClose={this.handleClose}>
|
||||
<If condition={!isHidden}>
|
||||
<BookmarkKeybindings></BookmarkKeybindings>
|
||||
</If>
|
||||
<div className="bookmarks-list">
|
||||
<For index="idx" each="bookmark" of={bookmarks}>
|
||||
<Bookmark key={bookmark.bookmarkid} bookmark={bookmark} />
|
||||
|
@ -205,43 +205,33 @@ class BookmarksModel {
|
||||
})();
|
||||
}
|
||||
|
||||
handleDocKeyDown(e: any): void {
|
||||
const waveEvent = adaptFromReactOrNativeKeyEvent(e);
|
||||
if (checkKeyPressed(waveEvent, "Escape")) {
|
||||
e.preventDefault();
|
||||
handleUserClose() {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
this.cancelEdit();
|
||||
return;
|
||||
}
|
||||
this.closeView();
|
||||
return;
|
||||
}
|
||||
|
||||
handleUserDelete() {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
return;
|
||||
}
|
||||
if (checkKeyPressed(waveEvent, "Backspace") || checkKeyPressed(waveEvent, "Delete")) {
|
||||
if (this.activeBookmark.get() == null) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
this.handleDeleteBookmark(this.activeBookmark.get());
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
checkKeyPressed(waveEvent, "ArrowUp") ||
|
||||
checkKeyPressed(waveEvent, "ArrowDown") ||
|
||||
checkKeyPressed(waveEvent, "PageUp") ||
|
||||
checkKeyPressed(waveEvent, "PageDown")
|
||||
) {
|
||||
e.preventDefault();
|
||||
handleUserNavigate(amt: number) {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
@ -255,31 +245,37 @@ class BookmarksModel {
|
||||
mobx.action(() => {
|
||||
this.activeBookmark.set(bm.bookmarkid);
|
||||
})();
|
||||
}
|
||||
|
||||
handleUserConfirm() {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
return;
|
||||
}
|
||||
if (checkKeyPressed(waveEvent, "Enter")) {
|
||||
if (this.activeBookmark.get() == null) {
|
||||
return;
|
||||
}
|
||||
this.useBookmark(this.activeBookmark.get());
|
||||
}
|
||||
|
||||
handleUserEdit() {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
return;
|
||||
}
|
||||
if (checkKeyPressed(waveEvent, "e")) {
|
||||
if (this.activeBookmark.get() == null) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
this.handleEditBookmark(this.activeBookmark.get());
|
||||
}
|
||||
|
||||
handleUserCopy() {
|
||||
if (this.editingBookmark.get() != null) {
|
||||
return;
|
||||
}
|
||||
if (checkKeyPressed(waveEvent, "c")) {
|
||||
if (this.activeBookmark.get() == null) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
this.handleCopyBookmark(this.activeBookmark.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { BookmarksModel };
|
||||
|
@ -491,9 +491,7 @@ class Model {
|
||||
this.modalsModel.popModal();
|
||||
return;
|
||||
}
|
||||
if (this.activeMainView.get() == "bookmarks") {
|
||||
this.bookmarksModel.handleDocKeyDown(e);
|
||||
}
|
||||
this.keybindManager.processKeyEvent(e, waveEvent);
|
||||
if (this.activeMainView.get() == "history") {
|
||||
this.historyViewModel.handleDocKeyDown(e);
|
||||
}
|
||||
@ -535,7 +533,6 @@ class Model {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.keybindManager.processKeyEvent(e, waveEvent);
|
||||
}
|
||||
|
||||
deleteActiveLine(): boolean {
|
||||
|
@ -38,7 +38,7 @@ type Keybind = {
|
||||
commandStr: string;
|
||||
};
|
||||
|
||||
const KeybindLevels = ["system", "modal", "app", "pane", "plugin"];
|
||||
const KeybindLevels = ["system", "modal", "app", "mainview", "pane", "plugin"];
|
||||
|
||||
class KeybindManager {
|
||||
domainCallbacks: Map<string, KeybindCallback>;
|
||||
@ -159,8 +159,6 @@ class KeybindManager {
|
||||
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
||||
if (curDomainCallback != null) {
|
||||
shouldReturn = curDomainCallback(event);
|
||||
} else {
|
||||
console.log("domain callback for ", curKeybind.domain, " is null. This should never happen");
|
||||
}
|
||||
}
|
||||
if (shouldRunCommand) {
|
||||
|
Loading…
Reference in New Issue
Block a user