diff --git a/platforms/android/app/src/main/java/com/foxdebug/acode/cursor/CursorController.kt b/platforms/android/app/src/main/java/com/foxdebug/acode/cursor/CursorController.kt new file mode 100644 index 000000000..81a86c839 --- /dev/null +++ b/platforms/android/app/src/main/java/com/foxdebug/acode/cursor/CursorController.kt @@ -0,0 +1,67 @@ +package com.foxdebug.acode.cursor + +import android.os.Build +import android.view.HapticFeedbackConstants +import androidx.annotation.Keep +import com.foxdebug.acode.runtime.Callback +import com.foxdebug.acode.runtime.Service +import org.json.JSONArray + +/** + * Plays the Quick Tools cursor controller's haptics through the platform's + * own feedback constants, so they feel like the rest of the system and follow + * the user's touch feedback setting. + */ +@Keep +class CursorController : Service() { + override fun execute(action: String, args: JSONArray, callback: Callback): Boolean { + if (action != ACTION_FEEDBACK) return false + val view = webView + val constant = feedbackConstant(args.optString(0)) + if (view != null && constant != null) { + view.post { view.performHapticFeedback(constant) } + } + callback.success() + return true + } + + private fun feedbackConstant(kind: String): Int? = when (kind) { + "tick" -> tick() + "edge" -> reject() + "select" -> HapticFeedbackConstants.LONG_PRESS + "start" -> HapticFeedbackConstants.VIRTUAL_KEY + "end" -> sinceOMr1(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE) + "confirm" -> confirm() + else -> null + } + + // TEXT_HANDLE_MOVE and CLOCK_TICK are silent on many devices, so caret + // steps use the slider tick, falling back to the context-click tick. + private fun tick(): Int = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + HapticFeedbackConstants.SEGMENT_TICK + } else { + HapticFeedbackConstants.CONTEXT_CLICK + } + + private fun reject(): Int = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + HapticFeedbackConstants.REJECT + } else { + HapticFeedbackConstants.LONG_PRESS + } + + private fun confirm(): Int = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + HapticFeedbackConstants.CONFIRM + } else { + HapticFeedbackConstants.VIRTUAL_KEY + } + + private fun sinceOMr1(constant: Int): Int? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) constant else null + + private companion object { + const val ACTION_FEEDBACK = "feedback" + } +} diff --git a/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceName.kt b/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceName.kt index 0c767084c..5a43a8381 100644 --- a/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceName.kt +++ b/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceName.kt @@ -9,6 +9,7 @@ enum class ServiceName(val key: String) { NATIVE_HTTP("NativeHttpPlugin"), BUILD_INFO("BuildInfo"), CRASH_HANDLER("CrashHandler"), + CURSOR_CONTROLLER("CursorController"), CUSTOM_TABS("CustomTabs"), DEVICE("Device"), FILE("File"), diff --git a/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceRegistry.kt b/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceRegistry.kt index 2e1e97b58..88db7755b 100644 --- a/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceRegistry.kt +++ b/platforms/android/app/src/main/java/com/foxdebug/acode/runtime/ServiceRegistry.kt @@ -4,6 +4,7 @@ import com.foxdebug.acode.auth.Authenticator import com.foxdebug.acode.browser.Plugin import com.foxdebug.acode.buildinfo.BuildInfo import com.foxdebug.acode.crashhandler.CrashHandler +import com.foxdebug.acode.cursor.CursorController import com.foxdebug.acode.customtabs.CustomTabsPlugin import com.foxdebug.acode.device.Device import com.foxdebug.acode.file.FileUtils @@ -28,6 +29,7 @@ object ServiceRegistry { ServiceDefinition(ServiceName.NATIVE_HTTP) { NativeHttpPlugin() }, ServiceDefinition(ServiceName.BUILD_INFO) { BuildInfo() }, ServiceDefinition(ServiceName.CRASH_HANDLER, loadOnStart = true) { CrashHandler() }, + ServiceDefinition(ServiceName.CURSOR_CONTROLLER) { CursorController() }, ServiceDefinition(ServiceName.CUSTOM_TABS) { CustomTabsPlugin() }, ServiceDefinition(ServiceName.DEVICE) { Device() }, ServiceDefinition(ServiceName.FILE, loadOnStart = true) { FileUtils() }, diff --git a/src/cm/cursorController/caretDrag.ts b/src/cm/cursorController/caretDrag.ts new file mode 100644 index 000000000..a5e47fc9a --- /dev/null +++ b/src/cm/cursorController/caretDrag.ts @@ -0,0 +1,138 @@ +import { + EditorSelection, + type EditorState, + type SelectionRange, + type TransactionSpec, +} from "@codemirror/state"; + +interface Coords { + left: number; + right: number; + top: number; + bottom: number; +} + +export interface CaretDragView { + state: EditorState; + scrollDOM: { scrollLeft: number }; + defaultLineHeight: number; + dispatch(spec: TransactionSpec): void; + moveVertically(start: SelectionRange, forward: boolean): SelectionRange; + coordsAtPos(pos: number, side?: -1 | 1): Coords | null; + posAtCoords(coords: { x: number; y: number }, precise: false): number | null; +} + +export interface CaretDragResult { + moved: boolean; + blocked: boolean; + changedRow: boolean; +} + +/** + * The caret follows the finger 1:1, with no speed curve. A position at a + * soft-wrap break belongs to two visual rows, so ranges keep their `assoc` + * to stay on the row the finger is on. + */ +export default class CaretDrag { + #view: CaretDragView; + #anchor: number | null = null; + #startX: number | null = null; + #startScrollLeft = 0; + #originY = 0; + #lineOffset = 0; + + constructor(view: CaretDragView) { + this.#view = view; + this.#captureStart(0); + } + + set extend(value: boolean) { + this.#anchor = value ? this.#view.state.selection.main.anchor : null; + } + + update(offsetX: number, offsetY: number): CaretDragResult { + const view = this.#view; + if (this.#startX == null) this.#captureStart(offsetX); + const { main } = view.state.selection; + const lineHeight = view.defaultLineHeight || 1; + const targetLines = Math.round((offsetY - this.#originY) / lineHeight); + let range = EditorSelection.cursor(main.head, main.assoc); + let blocked = false; + let changedRow = false; + + while (this.#lineOffset !== targetLines) { + const forward = targetLines > this.#lineOffset; + const next = view.moveVertically(range, forward); + if (this.#sameRow(range, next)) { + blocked = true; + this.#originY = offsetY - this.#lineOffset * lineHeight; + break; + } + range = next; + changedRow = true; + this.#lineOffset += forward ? 1 : -1; + } + + const target = this.#cursorAtX(range, offsetX) ?? range; + const { head, assoc } = target; + const anchor = Math.min(this.#anchor ?? head, view.state.doc.length); + const sameSide = anchor !== head || assoc < 0 === main.assoc < 0; + if (anchor === main.anchor && head === main.head && sameSide) { + return { moved: false, blocked, changedRow }; + } + view.dispatch({ + selection: EditorSelection.create([ + EditorSelection.range(anchor, head, undefined, undefined, assoc), + ]), + scrollIntoView: true, + userEvent: "select", + }); + return { moved: true, blocked, changedRow }; + } + + #captureStart(offsetX: number): void { + const view = this.#view; + const { main } = view.state.selection; + const coords = this.#coords(main.head, main.assoc); + if (!coords) return; + this.#startX = coords.left - offsetX; + this.#startScrollLeft = view.scrollDOM.scrollLeft; + } + + #sameRow(from: SelectionRange, to: SelectionRange): boolean { + if (from.head === to.head && from.assoc < 0 === to.assoc < 0) return true; + const before = this.#coords(from.head, from.assoc); + const after = this.#coords(to.head, to.assoc); + if (!before || !after) { + const { doc } = this.#view.state; + return doc.lineAt(from.head).number === doc.lineAt(to.head).number; + } + return this.#sameTop(before, after); + } + + #cursorAtX(range: SelectionRange, offsetX: number): SelectionRange | null { + const view = this.#view; + const row = this.#coords(range.head, range.assoc); + if (!row || this.#startX == null) return null; + const scrolled = view.scrollDOM.scrollLeft - this.#startScrollLeft; + const pos = view.posAtCoords( + { + x: this.#startX + offsetX - scrolled, + y: (row.top + row.bottom) / 2, + }, + false, + ); + if (pos == null) return null; + const after = view.coordsAtPos(pos, 1); + const endOfRow = !!after && !this.#sameTop(after, row); + return EditorSelection.cursor(pos, endOfRow ? -1 : 0); + } + + #coords(pos: number, assoc: number): Coords | null { + return this.#view.coordsAtPos(pos, assoc < 0 ? -1 : 1); + } + + #sameTop(a: Coords, b: Coords): boolean { + return Math.abs(a.top - b.top) < (this.#view.defaultLineHeight || 1) / 2; + } +} diff --git a/src/cm/cursorController/feedback.ts b/src/cm/cursorController/feedback.ts new file mode 100644 index 000000000..9b27b987e --- /dev/null +++ b/src/cm/cursorController/feedback.ts @@ -0,0 +1,45 @@ +import config from "lib/config"; +import appSettings from "lib/settings"; +import exec from "native/exec"; +import haptic from "utils/haptic"; + +export type CursorFeedback = + | "tick" + | "edge" + | "select" + | "start" + | "end" + | "confirm"; + +const TICK_INTERVAL_MS = 35; +const STRONG_FEEDBACK: CursorFeedback[] = ["edge", "select", "confirm"]; + +let lastTickTime = 0; + +/** + * Android plays the matching system haptic constant natively. Elsewhere the + * app's generic haptic stands in, with ticks throttled so quick drags don't buzz. + */ +export default function cursorFeedback(kind: CursorFeedback): void { + const { vibrateOnTap, cursorControllerHaptics } = appSettings.value; + if (!vibrateOnTap || !cursorControllerHaptics) return; + + const platformId = window.Bridge?.platformId; + if (platformId === "android") { + try { + exec(null, null, "CursorController", "feedback", [kind]); + } catch (error) { + console.error("Cursor controller feedback failed", error); + } + return; + } + + if (kind === "start" || kind === "end") return; + if (platformId !== "ios" && !STRONG_FEEDBACK.includes(kind)) return; + if (kind === "tick") { + const now = performance.now(); + if (now - lastTickTime < TICK_INTERVAL_MS) return; + lastTickTime = now; + } + haptic(config.VIBRATION_TIME); +} diff --git a/src/cm/touchSelectionMenu.js b/src/cm/touchSelectionMenu.js index 3b430abc8..f6adb6832 100644 --- a/src/cm/touchSelectionMenu.js +++ b/src/cm/touchSelectionMenu.js @@ -196,6 +196,7 @@ class TouchSelectionMenuController { #stateSyncRaf = 0; #isScrolling = false; #isPointerInteracting = false; + #isMenuHeld = false; #pointerSelectionSession = null; #readOnlyTapSession = null; #pendingPointerSelectionClick = null; @@ -311,6 +312,7 @@ class TouchSelectionMenuController { this.#menuRequested = false; this.#isPointerInteracting = false; this.#isScrolling = false; + this.#isMenuHeld = false; this.#clearMenuShowTimer(); cancelAnimationFrame(this.#stateSyncRaf); this.#stateSyncRaf = 0; @@ -365,6 +367,18 @@ class TouchSelectionMenuController { this.#hideMenu(); } + holdMenu(held) { + if (!this.#enabled || this.#canvas) return; + this.#isMenuHeld = !!held; + if (held) { + this.#clearMenuShowTimer(); + this.#cancelReadOnlyTap(); + this.#hideMenu(); + return; + } + if (this.#shouldShowMenu()) this.#scheduleMenuShow(MENU_SHOW_DELAY); + } + onScrollEnd() { if (!this.#enabled || this.#canvas || !this.#isScrolling) return; this.#isScrolling = false; @@ -405,6 +419,7 @@ class TouchSelectionMenuController { this.#menuRequested = false; this.#isPointerInteracting = false; this.#isScrolling = false; + this.#isMenuHeld = false; this.#clearMenuShowTimer(); this.#hideMenu(true); if (this.#canvas) this.#view.touchSelection?.hideMenu(); @@ -689,7 +704,9 @@ class TouchSelectionMenuController { } #shouldShowMenu() { - if (this.#isScrolling || this.#isPointerInteracting) return false; + if (this.#isScrolling || this.#isPointerInteracting || this.#isMenuHeld) { + return false; + } if (!this.#view.hasFocus && !this.#isReadOnly()) return false; if ( !this.#menuRequested && diff --git a/src/components/cursorController/index.js b/src/components/cursorController/index.js new file mode 100644 index 000000000..47b47b39a --- /dev/null +++ b/src/components/cursorController/index.js @@ -0,0 +1,237 @@ +import "./style.scss"; +import CaretDrag from "cm/cursorController/caretDrag"; +import cursorFeedback from "cm/cursorController/feedback"; +import keyboardHandler from "handlers/keyboard"; +import { key, setQuicktoolsUsed } from "handlers/quickTools"; +import appSettings from "lib/settings"; +import CursorIndicator from "./indicator"; +import CursorKnob from "./knob"; + +const HOLD_TO_SELECT_MS = 350; +const HOLD_SLOP_PX = 6; +const EDGE_FEEDBACK_MS = 170; +const GUARDED_EVENTS = ["touchstart", "click", "contextmenu"]; +const PLACEMENT_EVENTS = ["switch-file", "file-loaded"]; + +/** + * A pointing-stick knob on the Quick Tools seam. Once a touch starts on it, + * the knob captures the pointer, so the finger keeps steering the caret + * wherever it travels, including over the soft keyboard. + */ +export default class CursorController { + #knob = new CursorKnob(); + #indicator = new CursorIndicator(); + #gesture = null; + #frame = 0; + + mount($footer) { + this.#knob.mount($footer); + const $knob = this.#knob.element; + $knob.addEventListener("pointerdown", this.#begin); + for (const type of GUARDED_EVENTS) { + $knob.addEventListener(type, stopEvent, { passive: false }); + } + + new MutationObserver(this.#place).observe($footer, { childList: true }); + editorManager.on(PLACEMENT_EVENTS, this.#onFileChange); + appSettings.on("update:cursorController", this.#place); + keyboardHandler.on("keyboardShow", this.#place); + keyboardHandler.on("keyboardHide", this.#place); + $footer.addEventListener("transitionend", this.#onFooterTransition); + new ResizeObserver(this.#place).observe(root); + document.addEventListener("focusin", this.#onFocusChange); + document.addEventListener("focusout", this.#onFocusChange); + key.on("shift", this.#place); + this.#place(); + } + + #place = () => { + cancelAnimationFrame(this.#frame); + this.#frame = requestAnimationFrame(() => { + this.#knob.place(this.#shouldShow()); + }); + }; + + #onFooterTransition = (event) => { + if (event.target === event.currentTarget) this.#place(); + }; + + #onFocusChange = (event) => { + if (getEditorView()?.dom.contains(event.target)) this.#place(); + }; + + #onFileChange = () => { + if (this.#gesture) this.#finish(); + this.#place(); + }; + + #shouldShow() { + if (this.#gesture) return true; + if (!appSettings.value.cursorController) return false; + const view = getEditorView(); + return !!view && (view.hasFocus || key.shift); + } + + #begin = (event) => { + stopEvent(event); + if (this.#gesture) return; + + const view = getEditorView(); + if (!view) { + cursorFeedback("edge"); + this.#knob.bump(); + return; + } + + const $knob = this.#knob.element; + $knob.setPointerCapture(event.pointerId); + const gesture = { + view, + drag: new CaretDrag(view), + touchSelection: getTouchSelectionController(), + pointerId: event.pointerId, + startX: event.clientX, + startY: event.clientY, + offsetX: 0, + offsetY: 0, + dirty: false, + selecting: key.shift, + selectionMade: false, + edgeLatched: false, + edgeAt: 0, + holdTimer: 0, + frame: 0, + }; + this.#gesture = gesture; + if (gesture.selecting) { + gesture.drag.extend = true; + } else { + gesture.holdTimer = setTimeout(this.#startSelection, HOLD_TO_SELECT_MS); + } + + $knob.addEventListener("pointermove", this.#onMove); + $knob.addEventListener("pointerup", this.#onEnd); + $knob.addEventListener("pointercancel", this.#onEnd); + $knob.addEventListener("lostpointercapture", this.#onEnd); + this.#knob.setActive(true); + this.#knob.setSelecting(gesture.selecting); + gesture.touchSelection?.holdMenu(true); + this.#indicator.show(view, gesture.selecting); + cursorFeedback("start"); + }; + + #onMove = (event) => { + const gesture = this.#gesture; + if (!gesture || event.pointerId !== gesture.pointerId) return; + gesture.offsetX = event.clientX - gesture.startX; + gesture.offsetY = event.clientY - gesture.startY; + gesture.dirty = true; + this.#knob.lean(event.clientX, event.clientY); + if ( + gesture.holdTimer && + Math.hypot(gesture.offsetX, gesture.offsetY) > HOLD_SLOP_PX + ) { + clearTimeout(gesture.holdTimer); + gesture.holdTimer = 0; + } + this.#requestStep(gesture); + }; + + #requestStep(gesture) { + if (!gesture.frame) gesture.frame = requestAnimationFrame(this.#tick); + } + + #tick = () => { + const gesture = this.#gesture; + if (!gesture) return; + gesture.frame = 0; + if (!gesture.dirty || gesture.holdTimer) return; + gesture.dirty = false; + this.#step(gesture); + }; + + #step(gesture) { + const { view } = gesture; + setQuicktoolsUsed(); + const { moved, blocked, changedRow } = gesture.drag.update( + gesture.offsetX, + gesture.offsetY, + ); + + if (changedRow) gesture.edgeLatched = false; + const hitEdge = blocked && !gesture.edgeLatched; + if (hitEdge) { + gesture.edgeLatched = true; + gesture.edgeAt = performance.now(); + cursorFeedback("edge"); + this.#knob.bump(); + } + if (!moved) return; + + if (gesture.selecting) gesture.selectionMade = true; + if (performance.now() - gesture.edgeAt > EDGE_FEEDBACK_MS) { + cursorFeedback("tick"); + } + this.#indicator.show(view, gesture.selecting); + } + + #startSelection = () => { + const gesture = this.#gesture; + if (!gesture) return; + gesture.holdTimer = 0; + gesture.selecting = true; + gesture.drag.extend = true; + cursorFeedback("select"); + this.#knob.setSelecting(true); + this.#indicator.show(gesture.view, true); + this.#requestStep(gesture); + }; + + #onEnd = (event) => { + const gesture = this.#gesture; + if (event.pointerId !== gesture?.pointerId) return; + if (event.type === "pointerup" && gesture.dirty && !gesture.holdTimer) { + gesture.dirty = false; + this.#step(gesture); + } + this.#finish(); + }; + + #finish() { + const gesture = this.#gesture; + this.#gesture = null; + + const { view, pointerId } = gesture; + const $knob = this.#knob.element; + cancelAnimationFrame(gesture.frame); + clearTimeout(gesture.holdTimer); + $knob.removeEventListener("pointermove", this.#onMove); + $knob.removeEventListener("pointerup", this.#onEnd); + $knob.removeEventListener("pointercancel", this.#onEnd); + $knob.removeEventListener("lostpointercapture", this.#onEnd); + if ($knob.hasPointerCapture(pointerId)) + $knob.releasePointerCapture(pointerId); + + this.#knob.setActive(false); + this.#indicator.hide(); + + const selected = !view.state.selection.main.empty; + cursorFeedback(gesture.selectionMade && selected ? "confirm" : "end"); + gesture.touchSelection?.holdMenu(false); + this.#place(); + } +} + +function stopEvent(event) { + event.preventDefault(); + event.stopPropagation(); +} + +function getEditorView() { + const { editor, activeFile } = editorManager; + return activeFile?.type === "editor" ? editor : null; +} + +function getTouchSelectionController() { + return editorManager.activePane?.touchSelectionController; +} diff --git a/src/components/cursorController/indicator.js b/src/components/cursorController/indicator.js new file mode 100644 index 000000000..07c009220 --- /dev/null +++ b/src/components/cursorController/indicator.js @@ -0,0 +1,75 @@ +const BADGE_GAP = 10; +const BADGE_EDGE = 8; +const HIDE_DELAY_MS = 150; + +/** + * A caret and a `line:column` label drawn over the editor while the cursor + * knob is held. The canvas editor hides its own caret while the soft + * keyboard is closed, so the knob draws one to stay visible either way. + */ +export default class CursorIndicator { + #element =
; + #caret = ; + #hideTimer = 0; + #active = false; + + show(view, selecting) { + clearTimeout(this.#hideTimer); + this.#active = true; + if (!this.#element.isConnected) { + document.body.append(this.#caret, this.#element); + } + const { state } = view; + const { main } = state.selection; + const line = state.doc.lineAt(main.head); + const column = main.head - line.from + 1; + const selected = main.to - main.from; + this.#element.textContent = selected + ? `${line.number}:${column} · ${selected}` + : `${line.number}:${column}`; + this.#element.dataset.selecting = String(selecting); + view.requestMeasure({ + key: "cursor-controller-badge", + read: () => ({ + coords: view.coordsAtPos(main.head, main.assoc < 0 ? -1 : 1), + width: this.#element.offsetWidth, + height: this.#element.offsetHeight, + }), + write: (measured) => this.#place(measured), + }); + } + + hide() { + this.#active = false; + this.#setVisible(false); + clearTimeout(this.#hideTimer); + this.#hideTimer = setTimeout(() => { + this.#element.remove(); + this.#caret.remove(); + }, HIDE_DELAY_MS); + } + + #place({ coords, width, height }) { + if (!this.#active) return; + if (!coords) { + this.#setVisible(false); + return; + } + const centerX = (coords.left + coords.right) / 2; + const left = Math.min( + Math.max(centerX - width / 2, BADGE_EDGE), + innerWidth - width - BADGE_EDGE, + ); + const above = coords.top - BADGE_GAP - height; + const top = above >= BADGE_EDGE ? above : coords.bottom + BADGE_GAP; + this.#element.style.transform = `translate(${left}px, ${top}px)`; + this.#caret.style.height = `${coords.bottom - coords.top}px`; + this.#caret.style.transform = `translate(${coords.left}px, ${coords.top}px)`; + this.#setVisible(true); + } + + #setVisible(visible) { + this.#element.classList.toggle("visible", visible); + this.#caret.classList.toggle("visible", visible); + } +} diff --git a/src/components/cursorController/knob.js b/src/components/cursorController/knob.js new file mode 100644 index 000000000..55181dacf --- /dev/null +++ b/src/components/cursorController/knob.js @@ -0,0 +1,100 @@ +import quickTools from "components/quickTools"; + +const MAX_LEAN_PX = 3; +const LEAN_REACH_PX = 20; +const KNOB_RADIUS_PX = 10; +const BUMP_MS = 220; + +/** + * The cursor knob dot, centered on the seam between the Quick Tools + * rows. It floats over the rows, so the Quick Tools layout is untouched. + */ +export default class CursorKnob { + #element = ; + #footer = null; + #center = null; + #bumpTimer = 0; + + get element() { + return this.#element; + } + + mount($footer) { + this.#footer = $footer; + root.appendOuter(this.#element); + } + + place(visible) { + this.#apply(visible ? this.#measure() : null); + } + + lean(clientX, clientY) { + if (!this.#center) return; + const dx = reach(clientX - this.#center.x); + const dy = reach(clientY - this.#center.y); + const { style } = this.#element; + style.setProperty("--lean-x", `${dx * MAX_LEAN_PX}px`); + style.setProperty("--lean-y", `${dy * MAX_LEAN_PX}px`); + } + + setActive(active) { + this.#element.classList.toggle("active", active); + if (active) { + const rect = this.#element.getBoundingClientRect(); + this.#center = { + x: rect.left + rect.width / 2, + y: rect.top + rect.height / 2, + }; + return; + } + this.#center = null; + this.#element.style.removeProperty("--lean-x"); + this.#element.style.removeProperty("--lean-y"); + this.setSelecting(false); + } + + setSelecting(selecting) { + this.#element.dataset.selecting = String(selecting); + } + + bump() { + const $knob = this.#element; + $knob.classList.remove("bump"); + void $knob.offsetWidth; + $knob.classList.add("bump"); + clearTimeout(this.#bumpTimer); + this.#bumpTimer = setTimeout(() => $knob.classList.remove("bump"), BUMP_MS); + } + + #measure() { + const $footer = this.#footer; + const rows = [quickTools.$row1, quickTools.$row2].filter(($row) => + $footer.contains($row), + ); + if (!rows.length) return null; + + const rootRect = root.getBoundingClientRect(); + const footerRect = $footer.getBoundingClientRect(); + const firstRect = rows[0].getBoundingClientRect(); + const y = + rows.length > 1 ? firstRect.bottom : firstRect.top + KNOB_RADIUS_PX; + return { + x: footerRect.left + footerRect.width / 2 - rootRect.left, + bottom: rootRect.bottom - y, + rows: rows.length, + }; + } + + #apply(layout) { + this.#element.classList.toggle("hidden", !layout); + if (!layout) return; + const { style, dataset } = this.#element; + style.left = `${layout.x}px`; + style.bottom = `${layout.bottom}px`; + dataset.rows = String(layout.rows); + } +} + +function reach(offset) { + return Math.max(-1, Math.min(1, offset / LEAN_REACH_PX)); +} diff --git a/src/components/cursorController/style.scss b/src/components/cursorController/style.scss new file mode 100644 index 000000000..722be434c --- /dev/null +++ b/src/components/cursorController/style.scss @@ -0,0 +1,184 @@ +.cursor-knob { + position: fixed; + left: 0; + bottom: 0; + width: 20px; + height: 20px; + margin: 0 0 -10px -10px; + border-radius: 50%; + z-index: 99; + touch-action: none; + user-select: none; + -webkit-user-select: none; + -webkit-tap-highlight-color: transparent; + background: rgba(127, 127, 127, 0.22); + transition: + opacity 180ms ease, + scale 220ms cubic-bezier(0.2, 0.9, 0.3, 1.3), + background-color 160ms ease, + box-shadow 160ms ease; + + &::before { + content: ""; + position: absolute; + top: 3px; + right: 3px; + bottom: 3px; + left: 3px; + border-radius: 50%; + background-color: var(--primary-text-color); + background-image: + linear-gradient(var(--primary-color) 0.5px, transparent 0.5px), + linear-gradient(90deg, var(--primary-color) 0.5px, transparent 0.5px); + background-size: 2.5px 2.5px; + background-position: center; + box-shadow: + 0 2px 4px var(--box-shadow-color), + 0 1px 1px rgba(0, 0, 0, 0.3); + transform: translate(var(--lean-x, 0), var(--lean-y, 0)) rotate(15deg) scale(var(--press, 1)); + transition: + transform 120ms ease, + border-radius 160ms ease; + } + + &::after { + content: ""; + position: absolute; + top: -8px; + right: -8px; + bottom: -8px; + left: -8px; + border-radius: 50%; + } + + &[data-rows="1"]::after { + top: 0; + } + + &.hidden { + opacity: 0; + scale: 0.4; + pointer-events: none; + transition: + opacity 140ms ease, + scale 140ms ease-in; + } + + &.active { + background: rgba(127, 127, 127, 0.36); + + &::before { + --press: 1.2; + transition: transform 40ms linear; + } + } + + &[data-selecting="true"] { + box-shadow: inset 0 0 0 1.5px var(--active-color); + + &::before { + border-radius: 2px; + } + } + + &.bump::before { + animation: cursor-knob-bump 220ms ease; + } +} + +@keyframes cursor-knob-bump { + + 0%, + 100% { + top: 3px; + bottom: 3px; + } + + 25% { + top: 1px; + bottom: 5px; + } + + 75% { + top: 5px; + bottom: 1px; + } +} + +.cursor-controller-badge { + position: fixed; + left: 0; + top: 0; + z-index: 1000; + pointer-events: none; + padding: 2px 8px; + border-radius: 10px; + font-size: 12px; + font-weight: 600; + line-height: 18px; + font-variant-numeric: tabular-nums; + white-space: nowrap; + color: var(--popup-text-color); + background: var(--popup-background-color); + border: 1px solid var(--active-color); + box-shadow: 0 2px 8px var(--box-shadow-color); + opacity: 0; + transition: opacity 120ms ease; + + &.visible { + opacity: 1; + } + + &[data-selecting="true"] { + color: var(--popup-background-color); + background: var(--active-color); + } +} + +.cursor-controller-caret { + position: fixed; + left: 0; + top: 0; + width: 2px; + margin-left: -1px; + z-index: 1000; + pointer-events: none; + border-radius: 1px; + background: var(--active-color); + opacity: 0; + transition: opacity 120ms ease; + + &.visible { + opacity: 1; + } +} + +@supports (background: color-mix(in srgb, red 50%, transparent)) { + .cursor-knob { + background: color-mix(in srgb, var(--active-color) 22%, transparent); + + &.active { + background: color-mix(in srgb, var(--active-color) 36%, transparent); + } + } + + .cursor-controller-badge { + border-color: color-mix(in srgb, var(--active-color) 45%, transparent); + } + + .cursor-controller-caret { + box-shadow: 0 0 6px 1px color-mix(in srgb, var(--active-color) 60%, transparent); + } +} + +@media (prefers-reduced-motion: reduce) { + + .cursor-knob, + .cursor-knob.hidden, + .cursor-knob::before, + .cursor-controller-badge, + .cursor-controller-caret { + transition: none !important; + animation: none !important; + } +} diff --git a/src/handlers/quickTools.js b/src/handlers/quickTools.js index 724ccbefa..3210c00b6 100644 --- a/src/handlers/quickTools.js +++ b/src/handlers/quickTools.js @@ -1298,7 +1298,7 @@ function getInput() { return input || editorManager.editor.contentDOM; } -function setQuicktoolsUsed() { +export function setQuicktoolsUsed() { clearTimeout(quickToolUsedTimeout); quickToolUsed = true; quickToolUsedTimeout = setTimeout(() => { diff --git a/src/handlers/quickToolsInit.js b/src/handlers/quickToolsInit.js index d408f0f71..4d645c494 100644 --- a/src/handlers/quickToolsInit.js +++ b/src/handlers/quickToolsInit.js @@ -1,5 +1,6 @@ import { redoDepth, undoDepth } from "@codemirror/commands"; import { focusEditorIfEditable } from "cm/editorReadOnly"; +import CursorController from "components/cursorController"; import quickTools from "components/quickTools"; import { description } from "components/quickTools/items"; import { hideTooltip, showTooltip } from "components/tooltip"; @@ -172,6 +173,7 @@ export default function init() { }); root.append($footer); + new CursorController().mount($footer); if (appSettings.value.floatingButton) { root.appendOuter($toggler); } diff --git a/src/lang/ar-ye.json b/src/lang/ar-ye.json index eda2f7e23..665ea75bc 100644 --- a/src/lang/ar-ye.json +++ b/src/lang/ar-ye.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/az-az.json b/src/lang/az-az.json index be5a5f71c..b603c9151 100644 --- a/src/lang/az-az.json +++ b/src/lang/az-az.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/be-by.json b/src/lang/be-by.json index dd5fcdb87..f236cc549 100644 --- a/src/lang/be-by.json +++ b/src/lang/be-by.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/bn-bd.json b/src/lang/bn-bd.json index 3cab84bfa..ae2b8e47a 100644 --- a/src/lang/bn-bd.json +++ b/src/lang/bn-bd.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/cs-cz.json b/src/lang/cs-cz.json index 7c604601b..3732d19fb 100644 --- a/src/lang/cs-cz.json +++ b/src/lang/cs-cz.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/de-de.json b/src/lang/de-de.json index 04e468cce..c49c0faf9 100644 --- a/src/lang/de-de.json +++ b/src/lang/de-de.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/en-us.json b/src/lang/en-us.json index 0bf2c9a64..070e70246 100644 --- a/src/lang/en-us.json +++ b/src/lang/en-us.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/es-sv.json b/src/lang/es-sv.json index b1a752fb8..60ba172a5 100644 --- a/src/lang/es-sv.json +++ b/src/lang/es-sv.json @@ -932,5 +932,9 @@ "store network error": "No se pudo conectar con la tienda. Revisa tu conexión a internet e inténtalo de nuevo.", "store error code": "La solicitud a la tienda falló (código {code}). Inténtalo de nuevo.", "sponsor confirmation pending": "Tu patrocinio está registrado. La confirmación de la tienda sigue pendiente. Acode lo volverá a intentar cuando regreses a la aplicación o vuelvas a abrir la sección de Patrocinio. No se te cobrará de nuevo.", - "sponsor recovery failed": "No se pudo recuperar el patrocinio. Inténtalo de nuevo." + "sponsor recovery failed": "No se pudo recuperar el patrocinio. Inténtalo de nuevo.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/fr-fr.json b/src/lang/fr-fr.json index 849126618..f6991ff8d 100644 --- a/src/lang/fr-fr.json +++ b/src/lang/fr-fr.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/he-il.json b/src/lang/he-il.json index 397432a21..673bca14c 100644 --- a/src/lang/he-il.json +++ b/src/lang/he-il.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/hi-in.json b/src/lang/hi-in.json index c42d690ec..f5a4dfa15 100644 --- a/src/lang/hi-in.json +++ b/src/lang/hi-in.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/hu-hu.json b/src/lang/hu-hu.json index 5cd507295..5bb828277 100644 --- a/src/lang/hu-hu.json +++ b/src/lang/hu-hu.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/id-id.json b/src/lang/id-id.json index 64c496c2d..d9519209f 100644 --- a/src/lang/id-id.json +++ b/src/lang/id-id.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/index.d.ts b/src/lang/index.d.ts index 5a9e316f1..749f26977 100644 --- a/src/lang/index.d.ts +++ b/src/lang/index.d.ts @@ -936,6 +936,10 @@ declare type LangStrings = { "store error code": string; "sponsor confirmation pending": string; "sponsor recovery failed": string; + "cursor controller": string; + "cursor controller haptics": string; + "settings-info-app-cursor-controller": string; + "settings-info-app-cursor-controller-haptics": string; }; declare var strings: LangStrings; diff --git a/src/lang/ir-fa.json b/src/lang/ir-fa.json index 900f60085..5bdf99e70 100644 --- a/src/lang/ir-fa.json +++ b/src/lang/ir-fa.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/it-it.json b/src/lang/it-it.json index ba4afe554..50dac9248 100644 --- a/src/lang/it-it.json +++ b/src/lang/it-it.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/ja-jp.json b/src/lang/ja-jp.json index 17b76161a..dee055188 100644 --- a/src/lang/ja-jp.json +++ b/src/lang/ja-jp.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/ko-kr.json b/src/lang/ko-kr.json index 9bbf39488..691c0dbad 100644 --- a/src/lang/ko-kr.json +++ b/src/lang/ko-kr.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/ln-ln.json b/src/lang/ln-ln.json index 336ac7596..f4cdd8018 100644 --- a/src/lang/ln-ln.json +++ b/src/lang/ln-ln.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/ml-in.json b/src/lang/ml-in.json index 554c7bc59..62b1bf9e8 100644 --- a/src/lang/ml-in.json +++ b/src/lang/ml-in.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/mm-unicode.json b/src/lang/mm-unicode.json index 001df84dc..3931cdd5a 100644 --- a/src/lang/mm-unicode.json +++ b/src/lang/mm-unicode.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/mm-zawgyi.json b/src/lang/mm-zawgyi.json index 2ec79685a..830560901 100644 --- a/src/lang/mm-zawgyi.json +++ b/src/lang/mm-zawgyi.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/pl-pl.json b/src/lang/pl-pl.json index a79fb0369..36e70703e 100644 --- a/src/lang/pl-pl.json +++ b/src/lang/pl-pl.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/pt-br.json b/src/lang/pt-br.json index c4b66354c..0d183b1d8 100644 --- a/src/lang/pt-br.json +++ b/src/lang/pt-br.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/pu-in.json b/src/lang/pu-in.json index c4d2eb269..a83dc4952 100644 --- a/src/lang/pu-in.json +++ b/src/lang/pu-in.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/ru-ru.json b/src/lang/ru-ru.json index 8d4de5070..8d1affc05 100644 --- a/src/lang/ru-ru.json +++ b/src/lang/ru-ru.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/tl-ph.json b/src/lang/tl-ph.json index f373f44e5..c7390a413 100644 --- a/src/lang/tl-ph.json +++ b/src/lang/tl-ph.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/tr-tr.json b/src/lang/tr-tr.json index 9dcbe3fe0..a3ecf1de6 100644 --- a/src/lang/tr-tr.json +++ b/src/lang/tr-tr.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/uk-ua.json b/src/lang/uk-ua.json index f9d5e3153..e2f246985 100644 --- a/src/lang/uk-ua.json +++ b/src/lang/uk-ua.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/uz-uz.json b/src/lang/uz-uz.json index 4844d21ef..f4de3c31a 100644 --- a/src/lang/uz-uz.json +++ b/src/lang/uz-uz.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/vi-vn.json b/src/lang/vi-vn.json index e7eb21db6..2315d0d62 100644 --- a/src/lang/vi-vn.json +++ b/src/lang/vi-vn.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/zh-cn.json b/src/lang/zh-cn.json index 1c29a9f16..d3e7c9068 100644 --- a/src/lang/zh-cn.json +++ b/src/lang/zh-cn.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/zh-hant.json b/src/lang/zh-hant.json index 9e34a551f..eac50c076 100644 --- a/src/lang/zh-hant.json +++ b/src/lang/zh-hant.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lang/zh-tw.json b/src/lang/zh-tw.json index 809feef4b..e367b55ce 100644 --- a/src/lang/zh-tw.json +++ b/src/lang/zh-tw.json @@ -932,5 +932,9 @@ "store network error": "The store could not connect. Check your internet connection and try again.", "store error code": "The store request failed (code {code}). Please try again.", "sponsor confirmation pending": "Your sponsorship is registered. Store confirmation is still pending. Acode will retry when you return to the app or reopen Sponsorship. You will not be charged again.", - "sponsor recovery failed": "Unable to recover sponsorship. Please try again." + "sponsor recovery failed": "Unable to recover sponsorship. Please try again.", + "cursor controller": "Cursor controller", + "cursor controller haptics": "Cursor controller haptics", + "settings-info-app-cursor-controller": "Show a pointing-stick knob between the Quick Tools rows. Drag it to move the caret exactly with your finger; hold it still first to select text.", + "settings-info-app-cursor-controller-haptics": "Feel a tick each time the cursor controller moves the caret. Also follows Vibrate on tap and the system touch feedback setting." } diff --git a/src/lib/settings.js b/src/lib/settings.js index 49274e895..3b7a4435e 100644 --- a/src/lib/settings.js +++ b/src/lib/settings.js @@ -152,6 +152,8 @@ class Settings { openFileListPos: this.OPEN_FILE_LIST_POS_HEADER, quickTools: 2, quickToolsTriggerMode: this.QUICKTOOLS_TRIGGER_MODE_TOUCH, + cursorController: true, + cursorControllerHaptics: true, appFont: "", editorFont: "Roboto Mono", vibrateOnTap: true, diff --git a/src/settings/appSettings.js b/src/settings/appSettings.js index 619cd2dd0..f96209561 100644 --- a/src/settings/appSettings.js +++ b/src/settings/appSettings.js @@ -203,6 +203,20 @@ export default function otherSettings() { info: strings["settings-info-app-quick-tools-trigger-mode"], category: categories.quickTools, }, + { + key: "cursorController", + text: strings["cursor controller"], + checkbox: values.cursorController, + info: strings["settings-info-app-cursor-controller"], + category: categories.quickTools, + }, + { + key: "cursorControllerHaptics", + text: strings["cursor controller haptics"], + checkbox: values.cursorControllerHaptics, + info: strings["settings-info-app-cursor-controller-haptics"], + category: categories.quickTools, + }, { key: "quickToolsSettings", text: strings["shortcut buttons"], diff --git a/tests/unit/cursorControllerCaretDrag.test.ts b/tests/unit/cursorControllerCaretDrag.test.ts new file mode 100644 index 000000000..85298d37b --- /dev/null +++ b/tests/unit/cursorControllerCaretDrag.test.ts @@ -0,0 +1,192 @@ +import { + EditorSelection, + EditorState, + type SelectionRange, + type TransactionSpec, +} from "@codemirror/state"; +import CaretDrag from "cm/cursorController/caretDrag"; +import { describe, expect, it } from "vitest"; + +const CHAR_WIDTH = 8; +const LINE_HEIGHT = 20; + +describe("CaretDrag", () => { + it("puts the caret under the finger's horizontal offset", () => { + const view = createView("abcdef", 1); + const drag = new CaretDrag(view); + drag.update(CHAR_WIDTH * 2, 0); + expect(head(view)).toBe(3); + drag.update(-CHAR_WIDTH, 0); + expect(head(view)).toBe(0); + }); + + it("moves one line per line height of travel, with no speed-up", () => { + const view = createView("abc\ndef\nghi", 1); + const drag = new CaretDrag(view); + drag.update(0, LINE_HEIGHT * 0.4); + expect(head(view)).toBe(1); + drag.update(0, LINE_HEIGHT); + expect(head(view)).toBe(5); + drag.update(0, LINE_HEIGHT * 2); + expect(head(view)).toBe(9); + }); + + it("keeps the finger's column across short lines", () => { + const view = createView("abcdef\nab\nabcdef", 5); + const drag = new CaretDrag(view); + drag.update(0, LINE_HEIGHT); + expect(head(view)).toBe(9); + drag.update(0, LINE_HEIGHT * 2); + expect(head(view)).toBe(15); + }); + + it("extends from a fixed anchor while selecting", () => { + const view = createView("abcdef", 1); + const drag = new CaretDrag(view); + drag.extend = true; + drag.update(CHAR_WIDTH * 3, 0); + const { anchor, head: selectionHead } = view.state.selection.main; + expect([anchor, selectionHead]).toEqual([1, 4]); + }); + + it("reports the document edge and responds at once on the way back", () => { + const view = createView("abc\ndef", 1); + const drag = new CaretDrag(view); + expect(drag.update(0, -LINE_HEIGHT * 3).blocked).toBe(true); + expect(head(view)).toBe(1); + + drag.update(0, -LINE_HEIGHT * 2); + expect(head(view)).toBe(5); + }); + + it("reports a row change only when the caret changes rows", () => { + const view = createView("abc\ndef", 1); + const drag = new CaretDrag(view); + expect(drag.update(0, -LINE_HEIGHT).changedRow).toBe(false); + expect(drag.update(8, -LINE_HEIGHT).changedRow).toBe(false); + expect(drag.update(8, 0).changedRow).toBe(true); + }); + + it("moves between soft-wrapped rows without a false edge", () => { + const view = createWrappedView("abcd efghijkl mnopqrst", [5, 14], 13); + const drag = new CaretDrag(view); + expect(drag.update(0, -LINE_HEIGHT).blocked).toBe(false); + expect(head(view)).toBe(5); + expect(view.state.selection.main.assoc).toBe(-1); + + drag.update(0, 0); + expect(head(view)).toBe(13); + }); + + it("keeps a selection anchor inside a shrunken document", () => { + const view = createView("abc\ndef", 6); + const drag = new CaretDrag(view); + drag.extend = true; + view.state = EditorState.create({ + doc: "ab", + selection: EditorSelection.cursor(1), + }); + expect(() => drag.update(CHAR_WIDTH, 0)).not.toThrow(); + expect(view.state.selection.main.anchor).toBeLessThanOrEqual(2); + }); +}); + +function head(view: ReturnType