bugfixes and tooling

This commit is contained in:
fuwaa 2022-08-24 12:52:43 +08:00
parent d54742a189
commit a74d55639d
No known key found for this signature in database
GPG key ID: 7CE0BF0D3175E2DC
4 changed files with 116 additions and 15 deletions

View file

@ -9,17 +9,17 @@ export default Option = (props) => {
function execute() { function execute() {
modal.close(); modal.close();
if (category === "Application") { setTimeout(() => {
ipcRenderer.send("command", command, {}); if (category === "Application") {
} ipcRenderer.send("command", command, {});
}
if (category === "Core") {
if (selector === "body") { if (selector === "body") {
inkdrop.commands.dispatch(document.body, command); inkdrop.commands.dispatch(document.body, command);
} else { } else {
inkdrop.commands.dispatch(document.querySelector(selector), command); inkdrop.commands.dispatch(document.querySelector(selector), command);
} }
} }, 50);
// hide modal after executing // hide modal after executing
} }
@ -66,7 +66,7 @@ export default Option = (props) => {
if (key == "") return null; if (key == "") return null;
else else
return ( return (
<span> <span className="shortcut">
<kbd key={index}>{key}</kbd> <kbd key={index}>{key}</kbd>
{index !== shortcut.length - 1 ? " + " : ""} {index !== shortcut.length - 1 ? " + " : ""}
{console.log(key)} {console.log(key)}

View file

@ -2,15 +2,30 @@
import React, { useEffect, useCallback, useRef, useLayoutEffect } from "react"; import React, { useEffect, useCallback, useRef, useLayoutEffect } from "react";
import Option from "./command.js"; import Option from "./command.js";
import { logger, useModal } from "inkdrop";
import useArrowKeyNavigation from "../navigation/hook.js";
// commands list
import Application from "../commands/application.js"; import Application from "../commands/application.js";
import Core from "../commands/core.js"; import Core from "../commands/core.js";
import NoteTags from "../commands/notetagsbar.js"; import NoteTags from "../commands/notetagsbar.js";
import Formatting from "../commands/formatting.js"; import Formatting from "../commands/formatting.js";
import { logger, useModal } from "inkdrop"; import Editor from "../commands/editor.js";
import useArrowKeyNavigation from "../navigation/hook.js"; import ExportImport from "../commands/exportimport.js";
import View from "../commands/view.js";
import Window from "../commands/window.js";
const CommandPalette = (props) => { const CommandPalette = (props) => {
const Commands = [...Formatting, ...Application, ...Core, ...NoteTags]; const Commands = [
...Formatting,
...Editor,
...Application,
...Core,
...NoteTags,
...ExportImport,
...View,
...Window,
];
const modal = useModal(); const modal = useModal();
const { Dialog } = inkdrop.components.classes; const { Dialog } = inkdrop.components.classes;
@ -85,12 +100,44 @@ const CommandPalette = (props) => {
</div> </div>
<div className="cpContents"> <div className="cpContents">
{filteredResults.length === 0 ? ( {filteredResults.length === 0 ? (
<div className="nomatch"> <div className="nomatchwrapper">
<p className="nomatchemoji">{"(。><)"}</p> <div className="nomatch">
<p className="nomatchtext">no matching commands</p> <p className="nomatchemoji">{"(。><)"}</p>
<p className="nomatchtext"> <p className="nomatchtext">no matching commands</p>
try searching for a different term <p className="nomatchtext">
</p> try searching for a different term
</p>
</div>
<div className="nomatchfooter">
<p className="nomatchtext"> inkdrop command palette</p>
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
}}
className="nomatchtext"
>
<a
rel="noreferrer noopener"
href="https://github.com/fuwaa/inkdrop-command-palette"
target="_blank"
style={{ margin: "0px 5px" }}
>
star on github
</a>
<a
rel="noreferrer noopener"
href="https://github.com/fuwaa/inkdrop-command-palette/issues/new"
target="_blank"
style={{ margin: "0px 5px" }}
>
report an issue
</a>
</div>
</div>
</div> </div>
) : null} ) : null}
{filteredResults.map((Command, index) => { {filteredResults.map((Command, index) => {

View file

@ -81,6 +81,22 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.nomatchfooter {
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.nomatchwrapper {
height: 100%;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.nomatchemoji { .nomatchemoji {
font-size: 50px; font-size: 50px;
@ -92,3 +108,7 @@
color: var(--disabled-text-color); color: var(--disabled-text-color);
margin: 0; margin: 0;
} }
.shortcut {
font-size: 12.5px;
}

34
tools/main.py Normal file
View file

@ -0,0 +1,34 @@
from asyncio import current_task
from urllib.error import ContentTooShortError
with open("window.js", "a") as f:
x = open ("source.txt", "r")
previouseditor= ""
currenteditor = ""
currentselector = ""
f.write("\"use babel\";\n")
f.write("export default [\n")
# if line starts with "editor:" add line to editor.js
for line in x:
print(line);
print(currenteditor)
print(currentselector)
if line.startswith("window:"):
currenteditor = line[7:]
if line.startswith("Selector: "):
currentselector = line[10:]
if line.startswith("Selector:"):
f.write("{\n")
f.write("name: \">%s\",\n" % (currenteditor.replace("-", " ").capitalize().strip()))
f.write("category: \"Window\",\n")
f.write("command: \"window:%s\",\n" % (currenteditor.strip()))
f.write("selector: \"%s\",\n" % (currentselector.strip()))
f.write("state: \"inprogress\",\n")
f.write("shortcut: [\"\"],\n")
f.write("},\n")
# insert values into the string
# if currenteditor variable changes, add line to editor.js
f.write("];")