Skip to content

Commit

Permalink
Cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingislost committed Sep 12, 2021
1 parent b4634f1 commit 9b6e0b3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "workspaces-plus",
"name": "Workspaces Plus",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "0.9.12",
"description": "Quickly switch and manage workspaces",
"author": "NothingIsLost",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-workspaces-plus",
"version": "0.1.0",
"version": "0.1.1",
"description": "Quickly switch and manage workspaces",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export default class WorkspacesPlus extends Plugin {
var activeWorkspaceName = this.workspacePlugin.activeWorkspace; // active workspace name
if (!Object.keys(this.workspacePlugin.workspaces).includes(activeWorkspaceName)) return true;
var savedWorkspace = JSON.parse(JSON.stringify(this.workspacePlugin.workspaces[activeWorkspaceName]));
deleteProp(savedWorkspace, ["active", "dimension", "width"]);
deleteProp(currentWorkspace, ["active", "dimension", "width"]);
deleteProp(savedWorkspace, ["active", "dimension", "width", "pane-relief:history-v1"]);
deleteProp(currentWorkspace, ["active", "dimension", "width", "pane-relief:history-v1"]);
return !deepEqual(currentWorkspace, savedWorkspace); // via the fast-equals package
};
}
Expand Down
34 changes: 28 additions & 6 deletions src/modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Modal, FuzzySuggestModal, WorkspacePluginInstance, FuzzyMatch, Notice } from "obsidian";
import { App, Modal, FuzzySuggestModal, WorkspacePluginInstance, FuzzyMatch, Notice, Scope } from "obsidian";
import { createPopper, Instance as PopperInstance } from "@popperjs/core";
import { WorkspacesPlusSettings } from "./settings";

Expand Down Expand Up @@ -111,7 +111,8 @@ export default class WorkspacesPlusPluginModal extends FuzzySuggestModal<string>
constructor(app: App, settings: WorkspacesPlusSettings) {
super(app);
this.settings = settings;

//@ts-ignore
this.bgEl.parentElement.setAttribute("style", "background-color: transparent !important");
//@ts-ignore
this.bgEl.setAttribute("style", "background-color: transparent");
this.modalEl.classList.add("workspaces-plus-modal");
Expand All @@ -138,12 +139,30 @@ export default class WorkspacesPlusPluginModal extends FuzzySuggestModal<string>
},
]);
}
//@ts-ignore
this.scope.unregister(this.scope.keys[3]); // TODO: remove the existing enter keybinding more gracefully
this.scope = new Scope();
this.scope.register([], "Escape", evt => this.onEscape(evt));
this.scope.register([], "Enter", evt => this.useSelectedItem(evt));
this.scope.register(["Shift"], "Delete", this.deleteWorkspace.bind(this));
this.scope.register(["Shift"], "Enter", evt => this.useSelectedItem(evt));
this.scope.register(["Alt"], "Enter", evt => this.useSelectedItem(evt));
this.scope.register([], "ArrowUp", evt => {
if (!evt.isComposing) return this.chooser.setSelectedItem(this.chooser.selectedItem - 1), !1;
});
this.scope.register([], "ArrowDown", evt => {
if (!evt.isComposing) return this.chooser.setSelectedItem(this.chooser.selectedItem + 1), !1;
});
}

onEscape(evt: MouseEvent | KeyboardEvent) {
const evtTargetEl = evt.target as HTMLElement;
// if we're actively renaming a workspace, escape out of the rename
if (evtTargetEl.classList.contains("workspace-item") && evtTargetEl.contentEditable === "true") {
evtTargetEl.textContent = evtTargetEl.dataset.workspaceName;
evtTargetEl.contentEditable = "false";
return;
}
// otherwise, close the modal
this.close();
}

onSuggestionClick = function (evt: MouseEvent | KeyboardEvent, itemEl: HTMLElement) {
Expand All @@ -162,7 +181,7 @@ export default class WorkspacesPlusPluginModal extends FuzzySuggestModal<string>
};

open = () => {
(<any>this.app).keymap.pushScope(this.scope);
this.app.keymap.pushScope(this.scope);
document.body.appendChild(this.containerEl);
this.popper = createPopper(document.body.querySelector(".plugin-workspaces-plus"), this.modalEl, {
placement: "top-start",
Expand Down Expand Up @@ -196,7 +215,10 @@ export default class WorkspacesPlusPluginModal extends FuzzySuggestModal<string>
const newName = targetEl.textContent;
this.workspacePlugin.deleteWorkspace(originalName);
this.workspacePlugin.saveWorkspace(newName);
if (originalName === this.activeWorkspace) this.setWorkspace(newName);
if (originalName === this.activeWorkspace) {
this.setWorkspace(newName);
this.activeWorkspace = newName;
}
this.chooser.chooser.updateSuggestions();
targetEl.contentEditable = "false";
this.app.workspace.trigger("layout-change");
Expand Down
14 changes: 11 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
width: unset;
}

.workspaces-plus-modal .prompt-instruction:last-child {
margin-right: 0px;
}

.workspace-item.is-selected {
background-color: var(--background-secondary);
border-radius: 0.2em;
Expand Down Expand Up @@ -37,10 +41,10 @@
fill: var(--text-accent-hover);
}

.workspace-results {padding: 0 .1em;}
.workspace-results {padding: .1em .1em;}

.workspace-results:hover .rename-workspace,
.workspace-results:hover .delete-workspace {
.workspace-item.is-selected~.rename-workspace,
.workspace-item.is-selected~.delete-workspace {
opacity: 1;
}

Expand Down Expand Up @@ -93,3 +97,7 @@
border-radius: 0.2em;
box-shadow: 0 0 0 0.1px rgba(0, 0, 0, 0.1), 0 0 0 3px hsla(var(--accent-hsl), 0.15);
}

.workspace-item[contenteditable="true"]:focus~div {
display: none;
}
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.1.1": "0.9.12",
"0.1.0": "0.9.12",
"0.0.8": "0.9.12",
"0.0.7": "0.9.12",
Expand Down

0 comments on commit 9b6e0b3

Please sign in to comment.