Skip to content

Commit 2b1dee3

Browse files
authored
Merge branch 'main' into Patch-CN
2 parents 740e249 + bf6eec6 commit 2b1dee3

35 files changed

Lines changed: 302 additions & 12 deletions

‎src/components/quickTools/footer.js‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @typedef {import('html-tag-js/ref')} Ref
33
*/
44

5+
import { hideTooltip, showTooltip } from "components/tooltip";
56
import settings from "lib/settings";
6-
import items, { ref } from "./items";
7+
import items, { description, ref } from "./items";
78

89
/**
910
* Create a row with common buttons
@@ -41,9 +42,9 @@ export const Row = ({ row }) => {
4142
export const SearchRow1 = ({ inputRef }) => (
4243
<div className="button-container" id="search_row1">
4344
<input ref={inputRef} type="search" placeholder={strings.search} />
44-
<RowItem icon="arrow_back" action="search-prev" />
45-
<RowItem icon="arrow_forward" action="search-next" />
46-
<RowItem icon="settings" action="search-settings" />
45+
<RowItem id="search-prev" icon="arrow_back" action="search-prev" />
46+
<RowItem id="search-next" icon="arrow_forward" action="search-next" />
47+
<RowItem id="search-settings" icon="settings" action="search-settings" />
4748
</div>
4849
);
4950

@@ -54,8 +55,12 @@ export const SearchRow1 = ({ inputRef }) => (
5455
export const SearchRow2 = ({ inputRef, posRef, totalRef }) => (
5556
<div className="button-container" id="search_row2">
5657
<input ref={inputRef} type="text" placeholder={strings.replace} />
57-
<RowItem icon="replace" action="search-replace" />
58-
<RowItem icon="replace_all" action="search-replace-all" />
58+
<RowItem id="search-replace" icon="replace" action="search-replace" />
59+
<RowItem
60+
id="search-replace-all"
61+
icon="replace_all"
62+
action="search-replace-all"
63+
/>
5964
<div className="search-status">
6065
<span ref={posRef}>0</span>
6166
<span>of</span>
@@ -114,9 +119,18 @@ export function RowItem({ id, icon, letters, action, value, ref, repeat }) {
114119
data-action={action}
115120
data-repeat={repeat}
116121
vibrate="true"
122+
aria-label={id ? description(id) : ""}
117123
></button>
118124
);
125+
if (id) {
126+
$item.addEventListener("mouseenter", () => {
127+
showTooltip($item, description(id));
128+
});
119129

130+
$item.addEventListener("mouseleave", () => {
131+
hideTooltip();
132+
});
133+
}
120134
if (typeof value === "function") {
121135
$item.value = value;
122136
} else if (value !== undefined) {

‎src/components/tooltip/index.js‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import "./style.scss";
2+
import { animate } from "motion";
3+
4+
let tooltip;
5+
let rafId = null;
6+
7+
function createTooltip() {
8+
if (tooltip) return tooltip;
9+
10+
tooltip = document.createElement("div");
11+
tooltip.className = "acode-tooltip";
12+
document.body.appendChild(tooltip);
13+
14+
return tooltip;
15+
}
16+
17+
export function showTooltip(target, text) {
18+
if (!target || !text) return;
19+
20+
const $tooltip = createTooltip();
21+
22+
$tooltip.textContent = text;
23+
24+
const rect = target.getBoundingClientRect();
25+
26+
if (rafId !== null) {
27+
cancelAnimationFrame(rafId);
28+
}
29+
rafId = requestAnimationFrame(() => {
30+
const width = $tooltip.offsetWidth;
31+
const height = $tooltip.offsetHeight;
32+
33+
const left = Math.max(
34+
8,
35+
Math.min(
36+
window.innerWidth - width - 8,
37+
rect.left + rect.width / 2 - width / 2,
38+
),
39+
);
40+
41+
const top = Math.max(8, rect.top - height - 10);
42+
43+
$tooltip.style.left = `${left}px`;
44+
$tooltip.style.top = `${top}px`;
45+
if (document.body.classList.contains("no-animation")) {
46+
$tooltip.style.opacity = "1";
47+
$tooltip.style.transform = "translateY(0)";
48+
rafId = null;
49+
return;
50+
}
51+
animate(
52+
$tooltip,
53+
{
54+
opacity: 1,
55+
transform: "translateY(0px)",
56+
},
57+
{
58+
duration: 0.15,
59+
},
60+
);
61+
rafId = null;
62+
});
63+
}
64+
65+
export function hideTooltip() {
66+
if (!tooltip) return;
67+
68+
if (rafId !== null) {
69+
cancelAnimationFrame(rafId);
70+
rafId = null;
71+
}
72+
if (document.body.classList.contains("no-animation")) {
73+
tooltip.style.opacity = "0";
74+
tooltip.style.transform = "translateY(5px)";
75+
return;
76+
}
77+
animate(
78+
tooltip,
79+
{
80+
opacity: 0,
81+
transform: "translateY(5px)",
82+
},
83+
{
84+
duration: 0.15,
85+
},
86+
);
87+
}

‎src/components/tooltip/style.scss‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.acode-tooltip {
2+
position: fixed;
3+
4+
padding: 6px 10px;
5+
6+
background: var(--popup-background-color);
7+
color: var(--popup-text-color);
8+
border: 1px solid var(--popup-border-color);
9+
box-shadow: 0 0 4px var(--box-shadow-color);
10+
border-radius: var(--popup-border-radius);
11+
12+
font-size: 12px;
13+
14+
white-space: nowrap;
15+
16+
pointer-events: none;
17+
18+
opacity: 0;
19+
20+
transform: translateY(5px);
21+
22+
z-index: 999999;
23+
}
24+

‎src/handlers/quickToolsInit.js‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { redoDepth, undoDepth } from "@codemirror/commands";
22
import quickTools from "components/quickTools";
3+
import { description } from "components/quickTools/items";
4+
import { hideTooltip, showTooltip } from "components/tooltip";
35
import config from "lib/config";
46
import appSettings from "lib/settings";
57
import actions, { key } from "./quickTools";
@@ -18,6 +20,7 @@ let startTime;
1820
let contextmenuTimeout;
1921
let active = false; // is button already active
2022
let slide = 0;
23+
let longPress = false;
2124

2225
/**@type {HTMLElement} */
2326
let $row;
@@ -37,6 +40,7 @@ function reset() {
3740
touchMoved = undefined;
3841
contextmenuTimeout = null;
3942
active = false;
43+
longPress = false;
4044
}
4145

4246
function clearTouchFeedback() {
@@ -168,6 +172,7 @@ function onclick(e) {
168172
e.preventDefault();
169173
e.stopPropagation();
170174
click(e.target);
175+
hideTooltip();
171176
clearTimeout(timeout);
172177
}
173178

@@ -189,13 +194,17 @@ function touchstart(e) {
189194
e.preventDefault();
190195
e.stopPropagation();
191196

192-
if ($el.dataset.repeat === "true") {
193-
contextmenuTimeout = setTimeout(() => {
194-
if (touchMoved) return;
197+
contextmenuTimeout = setTimeout(() => {
198+
if (touchMoved) return;
199+
200+
longPress = true;
201+
showTooltip($el, description($el.dataset.id));
202+
203+
if ($el.dataset.repeat === "true") {
195204
contextmenu = true;
196205
oncontextmenu(e);
197-
}, CONTEXT_MENU_TIMEOUT);
198-
}
206+
}
207+
}, CONTEXT_MENU_TIMEOUT);
199208

200209
if ($el.classList.contains("active")) {
201210
active = true;
@@ -299,7 +308,7 @@ function touchend(e) {
299308
return;
300309
}
301310

302-
if ($touchstart !== $el || contextmenu) {
311+
if ($touchstart !== $el || contextmenu || longPress) {
303312
touchcancel(e);
304313
return;
305314
}
@@ -320,6 +329,7 @@ function touchcancel(e) {
320329
clearTimeout(timeout);
321330
clearTimeout(contextmenuTimeout);
322331
clearTouchFeedback();
332+
hideTooltip();
323333
}
324334

325335
/**

‎src/lang/ar-ye.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"quicktools:exclamation": "إدراج علامة تعجب !",
383383
"quicktools:alt-key": "مفتاح Alt",
384384
"quicktools:meta-key": "مفتاح Windows/Meta",
385+
"quicktools:search-prev": "Previous Match",
386+
"quicktools:search-next": "Next Match",
387+
"quicktools:search-settings": "Search Settings",
388+
"quicktools:search-replace": "Replace",
389+
"quicktools:search-replace-all": "Replace All",
385390
"info-quicktoolssettings": "خصص أزرار الاختصارات ومفاتيح لوحة التحكم في شريط الأدوات السريع أسفل المحرر.",
386391
"info-excludefolders": "استخدم النمط **/node_modules/** لتجاهل ملفات مجلد node_modules في القائمة والبحث.",
387392
"missed files": "تم فحص {count} ملفاً بعد بدء البحث ولن يتم تضمينها في النتائج.",

‎src/lang/be-by.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"quicktools:exclamation": "Уставіць клічнік",
383383
"quicktools:alt-key": "Alt",
384384
"quicktools:meta-key": "Windows (Meta)",
385+
"quicktools:search-prev": "Previous Match",
386+
"quicktools:search-next": "Next Match",
387+
"quicktools:search-settings": "Search Settings",
388+
"quicktools:search-replace": "Replace",
389+
"quicktools:search-replace-all": "Replace All",
385390
"info-quicktoolssettings": "Наладзьце спалучэнні клавішы і клавішы клавіятуры ў кантэйнеры хуткіх інструментаў пад рэдактарам, каб павысіць зручнасць працы.",
386391
"info-excludefolders": "Выкарыстоўвайце шаблон **/node_modules/**, каб ігнараваць усе файлы з каталога node_modules. Гэта выключыць файлы са спіса і пошуку файлаў.",
387392
"missed files": "Ад пачатку пошуку апрацавана {count} файлаў. Яны не будуць уключаны ў пошук.",

‎src/lang/bn-bd.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"quicktools:exclamation": "আশ্চর্যবোধক চিহ্ন যোগ করুন",
383383
"quicktools:alt-key": "আল্ট কী",
384384
"quicktools:meta-key": "উইন্ডোজ/মেটা কী",
385+
"quicktools:search-prev": "Previous Match",
386+
"quicktools:search-next": "Next Match",
387+
"quicktools:search-settings": "Search Settings",
388+
"quicktools:search-replace": "Replace",
389+
"quicktools:search-replace-all": "Replace All",
385390
"info-quicktoolssettings": "সম্পাদকের নিচে Quicktools কন্টেইনারে শর্টকাট বাটন এবং কীবোর্ড কী কাস্টমাইজ করুন, যাতে কোডিং অভিজ্ঞতা উন্নত হয়।",
386391
"info-excludefolders": "node_modules ফোল্ডারের সব ফাইল উপেক্ষা করতে /node_modules/ প্যাটার্ন ব্যবহার করুন। এটি ফাইলগুলো তালিকাভুক্ত হতে বাধা দেবে এবং সার্চে অন্তর্ভুক্ত হবে না।",
387392
"missed files": "সার্চ শুরু হওয়ার পরে {count} ফাইল স্ক্যান করা হয়েছে এবং সার্চে অন্তর্ভুক্ত হবে না।",

‎src/lang/cs-cz.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"quicktools:exclamation": "Vložit vykřičník",
383383
"quicktools:alt-key": "Klávesa Alt",
384384
"quicktools:meta-key": "Klávesa Windows/Meta",
385+
"quicktools:search-prev": "Previous Match",
386+
"quicktools:search-next": "Next Match",
387+
"quicktools:search-settings": "Search Settings",
388+
"quicktools:search-replace": "Replace",
389+
"quicktools:search-replace-all": "Replace All",
385390
"info-quicktoolssettings": "V rychlých nástrojích pod editorem si můžete přizpůsobit tlačítka a klávesové zkratky.",
386391
"info-excludefolders": "Použijte vzor **/node_modules/** pro ignorování všech souborů ze složky node_modules. Tím se soubory vyloučí ze seznamu a také zabrání jejich zahrnutí do vyhledávání souborů.",
387392
"missed files": "Po zahájení vyhledávání bylo naskenováno {count} souborů, které nebudou zahrnuty do vyhledávání.",

‎src/lang/de-de.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@
382382
"quicktools:exclamation": "Ausrufezeichen einfügen",
383383
"quicktools:alt-key": "Alt-Taste",
384384
"quicktools:meta-key": "Windows-Taste",
385+
"quicktools:search-prev": "Previous Match",
386+
"quicktools:search-next": "Next Match",
387+
"quicktools:search-settings": "Search Settings",
388+
"quicktools:search-replace": "Replace",
389+
"quicktools:search-replace-all": "Replace All",
385390
"info-quicktoolssettings": "Anpassen der Schnellwahl-Schaltflächen und -Tasten im Schnellwerkzeug-Container unterhalb des Editors, um Ihre Programmiererfahrung zu verbessern.",
386391
"info-excludefolders": "Benutzen Sie das Muster **/node_modules/**, um alle Dateien im Ordner node_modules auszuschließen. Dadurch werden die Dateien nicht aufgelistet und auch nicht in die Dateisuche einbezogen.",
387392
"missed files": "Nach Beginn der Suche wurden {count} Dateien gescannt und werden nicht in die Suche einbezogen.",

‎src/lang/en-us.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@
394394
"quicktools:exclamation": "Insert exclamation",
395395
"quicktools:alt-key": "Alt key",
396396
"quicktools:meta-key": "Windows/Meta key",
397+
"quicktools:search-prev": "Previous Match",
398+
"quicktools:search-next": "Next Match",
399+
"quicktools:search-settings": "Search Settings",
400+
"quicktools:search-replace": "Replace",
401+
"quicktools:search-replace-all": "Replace All",
397402
"info-quicktoolssettings": "Customize shortcut buttons and keyboard keys in the Quicktools container below the editor to enhance your coding experience.",
398403
"info-excludefolders": "Use the pattern **/node_modules/** to ignore all files from the node_modules folder. This will exclude the files from being listed and will also prevent them from being included in file searches.",
399404
"missed files": "Scanned {count} files after search started and will not be included in search.",

0 commit comments

Comments
 (0)