Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/components/quickTools/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default [
item("modulo", "letters", "insert", "%", "%"),
item("caret", "letters", "insert", "^", "^"),
item("hyphen", "letters", "insert", "-", "-"),
item("paste", "paste", "command", "paste"),
];

/**
Expand All @@ -54,7 +55,7 @@ export default [
* @returns
*/
export function description(id) {
return strings[`quicktools:${id}`];
return strings[`quicktools:${id}`] || strings[id];
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/components/quickTools/style.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
@use '../../styles/mixins.scss';

#quick-tools {
.icon.click {
.icon.click:not([disabled]) {
@include mixins.active-icon;
transition: all 0.3s ease-in-out;
transform: scale(1.2);
}

[disabled] {
cursor: default;
opacity: 0.45;
}

[data-id="paste"] {
font-size: 0.9em;
}

&[data-alt="true"] {
[data-id="alt-key"] {
@include mixins.active-icon;
Expand Down Expand Up @@ -36,4 +45,4 @@
@include mixins.icon-badge;
}
}
}
}
19 changes: 19 additions & 0 deletions src/components/searchbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,29 @@ function searchBar($list, setHide, onhideCb, searchFunction) {
function cloneSearchItem($item) {
const $clone = $item.cloneNode(true);
$clone.addEventListener("click", () => {
$item.addEventListener(
"settings-item-interaction-end",
(event) => {
if (event.detail?.updated) {
syncSearchClone($clone, $item);
}
},
{ once: true },
);
$item.click();
});
return $clone;
}

/**
* Keep a visible search-result clone in sync after the backing item updates.
* @param {HTMLElement} $clone
* @param {HTMLElement} $item
*/
function syncSearchClone($clone, $item) {
$clone.className = $item.className;
$clone.innerHTML = $item.innerHTML;
}
}

export default searchBar;
18 changes: 16 additions & 2 deletions src/components/settingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,31 @@ function listItems($list, items, callback, options = {}) {
const item = itemByKey.get(key);
if (!item) return;
const result = await resolveItemInteraction(item, $target);
if (result.shouldCallCallback === false) return;
if (!result.shouldUpdateValue)
if (result.shouldCallCallback === false) {
dispatchItemInteractionEnd($target, false);
return;
}
if (!result.shouldUpdateValue) {
dispatchItemInteractionEnd($target, false);
return callback.call($target, key, item.value);
}

item.value = result.value;
updateItemValueDisplay($target, item, options, useInfoAsDescription);
dispatchItemInteractionEnd($target, true);

callback.call($target, key, item.value);
}
}

function dispatchItemInteractionEnd($target, updated) {
$target.dispatchEvent(
new CustomEvent("settings-item-interaction-end", {
detail: { updated },
}),
);
}

function normalizeSettings(settings) {
/** @type {string | undefined} */
let note;
Expand Down
48 changes: 39 additions & 9 deletions src/handlers/quickTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export let quickToolUsed = false;
let input;
/** @type {number} */
let quickToolUsedTimeout = null;
let activeSearchState = null;

const state = {
shift: false,
Expand Down Expand Up @@ -348,6 +349,7 @@ function toggleSearch() {
const { className } = quickTools.$toggler;
const $content = [...$footer.children];
const footerHeight = getFooterHeight();
activeSearchState = { className, content: $content, footerHeight };

$toggler.className = "floating icon clearclose";
$footer.content = [$searchRow1, $searchRow2];
Expand Down Expand Up @@ -375,10 +377,16 @@ function toggleSearch() {
actionStack.push({
id: "search-bar",
action: () => {
const restoreState = activeSearchState || {
className,
content: $content,
footerHeight,
};
removeSearch();
$footer.content = $content;
$toggler.className = className;
setFooterHeight(footerHeight);
$footer.content = restoreState.content;
$toggler.className = restoreState.className;
setFooterHeight(restoreState.footerHeight);
activeSearchState = null;
},
});
} else {
Expand Down Expand Up @@ -427,17 +435,30 @@ function setHeight(height = 1, save = true) {
save = false;
}

const searchBar = actionStack.get("search-bar");
if (searchBar?.action) {
if (height === 0) {
searchBar.action();
} else {
const footerHeight = Number(height) || 0;
activeSearchState = {
className:
activeSearchState?.className || quickTools.$toggler.className,
content: getQuickToolsRows(footerHeight),
footerHeight,
};
if (save) {
appSettings.update({ quickTools: height }, false);
}
return;
}
}

setFooterHeight(height);
if (save) {
appSettings.update({ quickTools: height }, false);
}

if (!height) {
$row1.remove();
$row2.remove();
return;
}

if (height >= 1) {
$row1.style.scrollBehavior = "unset";
$footer.append($row1);
Expand All @@ -446,6 +467,8 @@ function setHeight(height = 1, save = true) {
10,
);
--height;
} else {
$row1.remove();
}

if (height >= 1) {
Expand All @@ -456,9 +479,16 @@ function setHeight(height = 1, save = true) {
10,
);
--height;
} else {
$row2.remove();
}
}

function getQuickToolsRows(height) {
const { $row1, $row2 } = quickTools;
return [$row1, $row2].slice(0, height);
}

/**
* Removes search bar from footer
*/
Expand Down
45 changes: 44 additions & 1 deletion src/handlers/quickToolsInit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { redoDepth, undoDepth } from "@codemirror/commands";
import quickTools from "components/quickTools";
import config from "lib/config";
import appSettings from "lib/settings";
Expand Down Expand Up @@ -78,14 +79,26 @@ export default function init() {
} else {
$footer.removeAttribute("data-unsaved");
}
updateHistoryButtons();
});

editorManager.on("save-file", () => {
$footer.removeAttribute("data-unsaved");
});

root.append($footer, $toggler);
editorManager.on("editor-state-changed", updateHistoryButtons);

appSettings.on("update:quicktoolsItems:after", () => {
setTimeout(updateHistoryButtons, 100);
});

root.append($footer);
if (appSettings.value.floatingButton) {
root.appendOuter($toggler);
}
document.body.append($input);
setTimeout(updateHistoryButtons, 0);

if (
appSettings.value.quickToolsTriggerMode ===
appSettings.QUICKTOOLS_TRIGGER_MODE_CLICK
Expand Down Expand Up @@ -136,6 +149,12 @@ function onwheel(e) {
function onclick(e) {
reset();

if (e.target.disabled) {
e.preventDefault();
e.stopPropagation();
return;
}

e.preventDefault();
e.stopPropagation();
click(e.target);
Expand All @@ -149,6 +168,11 @@ function touchstart(e) {
if ($el instanceof HTMLInputElement) {
return;
}
if ($el.disabled) {
e.preventDefault();
e.stopPropagation();
return;
}

startTime = performance.now();
$touchstart = $el;
Expand Down Expand Up @@ -326,6 +350,8 @@ function oncontextmenu(e) {
* @param {HTMLElement} $el
*/
function click($el) {
if ($el.disabled) return;

$el.classList.add("click");
clearTimeout($el.dataset.timeout);
$el.dataset.timeout = setTimeout(() => {
Expand All @@ -347,3 +373,20 @@ function click($el) {

actions(action, value);
}

function updateHistoryButtons() {
const { editor, activeFile } = editorManager;
const disabled = !editor || activeFile?.type !== "editor";

updateHistoryButton("undo", disabled || undoDepth(editor.state) === 0);
updateHistoryButton("redo", disabled || redoDepth(editor.state) === 0);
}

function updateHistoryButton(id, disabled) {
quickTools.$footer
.querySelectorAll(`[data-id="${id}"]`)
.forEach(($button) => {
$button.disabled = disabled;
$button.setAttribute("aria-disabled", String(disabled));
});
}
7 changes: 5 additions & 2 deletions src/lang/ar-ye.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"none": "بلا",
"small": "صغير",
"large": "كبير",
"floating button": "الزر العائم",
"confirm on exit": "تأكيد عند الخروج",
"show console": "إظهار وحدة التحكم",
"image": "صورة",
Expand Down Expand Up @@ -760,5 +759,9 @@
"scrollbar height": "Scrollbar height",
"full": "Full",
"scroll past end": "Scroll past end",
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top."
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top.",
"compact": "مضغوط",
"off": "إيقاف",
"quick tools height": "ارتفاع الأدوات السريعة",
"quick tools toggler": "مبدل الأدوات السريعة"
}
7 changes: 5 additions & 2 deletions src/lang/be-by.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"none": "Няма",
"small": "Маленькі",
"large": "Вялікі",
"floating button": "Выплыўная панэль кнопак",
"confirm on exit": "Пацвярджэнне выхаду",
"show console": "Паказваць кансоль",
"image": "Выява",
Expand Down Expand Up @@ -760,5 +759,9 @@
"scrollbar height": "Scrollbar height",
"full": "Full",
"scroll past end": "Scroll past end",
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top."
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top.",
"compact": "Кампактны",
"off": "Выкл",
"quick tools height": "Вышыня хуткіх інструментаў",
"quick tools toggler": "Пераключальнік хуткіх інструментаў"
}
7 changes: 5 additions & 2 deletions src/lang/bn-bd.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"none": "none",
"small": "ছোট",
"large": "বড়",
"floating button": "ভাসমান বাটোন",
"confirm on exit": "প্রস্থান নিশ্চিত করুন",
"show console": "কনসোল দেখান",
"image": "ছবি",
Expand Down Expand Up @@ -760,5 +759,9 @@
"scrollbar height": "Scrollbar height",
"full": "Full",
"scroll past end": "Scroll past end",
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top."
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top.",
"compact": "কম্প্যাক্ট",
"off": "বন্ধ",
"quick tools height": "কুইক টুলসের উচ্চতা",
"quick tools toggler": "কুইক টুলস টগলার"
}
7 changes: 5 additions & 2 deletions src/lang/cs-cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"none": "Žádná",
"small": "Malá",
"large": "Velká",
"floating button": "Plovoucí tlačítko",
"confirm on exit": "Potvrdit při zavření",
"show console": "Zobrazit konzoli",
"image": "Obrázek",
Expand Down Expand Up @@ -760,5 +759,9 @@
"scrollbar height": "Scrollbar height",
"full": "Full",
"scroll past end": "Scroll past end",
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top."
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top.",
"compact": "Kompaktní",
"off": "Vypnuto",
"quick tools height": "Výška rychlých nástrojů",
"quick tools toggler": "Přepínač rychlých nástrojů"
}
7 changes: 5 additions & 2 deletions src/lang/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"none": "Keiner",
"small": "Klein",
"large": "Groß",
"floating button": "Schwebende Schaltfläche",
"confirm on exit": "Bestätigung beim Beenden",
"show console": "Konsole anzeigen",
"image": "Bild",
Expand Down Expand Up @@ -760,5 +759,9 @@
"scrollbar height": "Scrollbar height",
"full": "Full",
"scroll past end": "Scroll past end",
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top."
"settings-info-scroll-past-end": "Adds extra empty space at the bottom of the editor, allowing you to scroll the last line to the top.",
"compact": "Kompakt",
"off": "Aus",
"quick tools height": "Schnelltools-Höhe",
"quick tools toggler": "Schnelltools-Umschalter"
}
Loading