Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate highlightr custom menu item to Obsidian menu item #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions src/ui/highlighterMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,24 @@ const highlighterMenu = (
app: App,
plugin: HighlightrPlugin,
settings: HighlightrSettings,
editor: Editor,
event: MouseEvent
editor: Editor
): void => {
if (editor && editor.hasFocus()) {
const cursor = editor.getCursor("from");
let coords: Coords;
const editorCli = editor as any;

const menu = new Menu(plugin.app).addItem((item) => {
const itemDom = (item as any).dom as HTMLElement;
itemDom.setAttribute("style", "display: none");
});

const menuDom = (menu as any).dom as HTMLElement;
menuDom.addClass("highlighterContainer");
const menu = new Menu(plugin.app);
(menu as any).dom.addClass('highlighterContainer');

settings.highlighterOrder.forEach((highlighter) => {
const colorButton = menuDom.createEl("div");
colorButton.setAttribute("id", `${highlighter}`);

colorButton.addEventListener("click", function (event) {
(app as any).commands.executeCommandById(
`highlightr-plugin:${highlighter}`
);
menu.addItem((item) => {
item.setTitle(highlighter);
item.setIcon(`highlightr-pen-${highlighter}`.toLowerCase());
item.onClick(() => {
(app as any).commands.executeCommandById(`highlightr-plugin:${highlighter}`);
});
});

const colorButtonIcon = colorButton.createEl("span");
colorButtonIcon.innerHTML =
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" width="1.15em" height="1.15em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><title>' +
highlighter +
'</title><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10s-4.477 10-10 10zm0-2a8 8 0 1 0 0-16a8 8 0 0 0 0 16zm0-3a5 5 0 1 1 0-10a5 5 0 0 1 0 10z"/></svg>';
colorButtonIcon.setAttribute(
"style",
"margin-right: 10px; vertical-align: -.15em; display: inline-flex;"
);
colorButtonIcon.style.fill = settings.highlighters[highlighter];

const colorButtonText = colorButton.createEl("span");
colorButtonText.innerHTML = highlighter;
colorButtonText.setAttribute("style", "font-weight: 400;");
});

if (editorCli.cursorCoords) {
Expand Down
43 changes: 0 additions & 43 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,49 +185,6 @@ details[open] summary.highlight-summary::before {
}
}

.menu.highlighterContainer {
position: fixed;
width: 140px;
max-width: 225px;
max-height: 180px;
z-index: var(--layer-menu);
display: inline-block;
user-select: none;
overflow: hidden;
}

.menu.highlighterContainer {
min-width: 140px;
max-width: 225px;
max-height: 180px;
padding-left: 0em;
padding: 0;
margin: 0 auto;
border-radius: 6px;
font-size: 14px;
overflow-y: auto;
overflow-x: hidden;
position: fixed;
animation: fade 300ms ease-in-out;
background-color: var(--background-primary);
box-shadow: 0px 3px 25px rgba(31, 38, 135, 0.1);
border: 1px solid var(--background-modifier-border);
}

.menu.highlighterContainer div {
padding: 16px;
padding-top: 7px;
padding-bottom: 7px;
cursor: pointer;
text-align: left;
list-style-type: none;
border-bottom: 1px solid var(--background-modifier-border);
}

.menu.highlighterContainer div:last-child {
border-bottom: none;
}

/*----------------------------------------------------------------
SETTINGS TAB
----------------------------------------------------------------*/
Expand Down