AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Fallback to native mobile text input
yomae23e966afec7
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex bd80f6d5..d4a6d581 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -508,7 +508,6 @@ export const EditorPane = ({const [mobilePlainText, setMobilePlainText] = useState("");const [mobileToolbarOpen, setMobileToolbarOpen] = useState(false);const [mobileImeDebugOpen, setMobileImeDebugOpen] = useState(false);- const [mobileImeBridgeReady, setMobileImeBridgeReady] = useState(false);const [mobileImeDebugActiveElement, setMobileImeDebugActiveElement] = useState(getActiveElementLabel);const [mobileImeDebugEvents, setMobileImeDebugEvents] = useState<MobileImeDebugEntry[]>([]);const notebookOptions = useMemo(() => getNotebookMoveOptions(notebooks), [notebooks]);@@ -520,9 +519,7 @@ export const EditorPane = ({const memoRef = useRef<MemoDetail | null>(memo);const editorRef = useRef<Editor | null>(null);- const mobileTextAreaRef = useRef<HTMLDivElement | null>(null);- const mobileImeBridgeInputRef = useRef<HTMLInputElement | null>(null);- const mobileImeBridgeComposingRef = useRef(false);+ const mobileTextAreaRef = useRef<MobilePlainTextElement | null>(null);const mobileDraftTimerRef = useRef<number | null>(null);const mobileSaveTimerRef = useRef<number | null>(null);const mobileImeDebugEventIdRef = useRef(0);@@ -537,23 +534,9 @@ export const EditorPane = ({const imageCompressionEnabledRef = useRef(imageCompressionEnabled);const focusMobileInputTarget = useCallback(() => {- const bridgeInput = mobileImeBridgeInputRef.current;- if (bridgeInput) {- bridgeInput.focus({ preventScroll: true });- bridgeInput.setSelectionRange(bridgeInput.value.length, bridgeInput.value.length);- return;- }-- focusMobilePlainTextElement(mobileTextAreaRef.current);- }, []);-- const bindMobileImeBridgeInput = useCallback((element: HTMLInputElement | null) => {- if (mobileImeBridgeInputRef.current === element) {- return;+ if (mobileTextAreaRef.current) {+ focusMobilePlainTextElement(mobileTextAreaRef.current);}-- mobileImeBridgeInputRef.current = element;- setMobileImeBridgeReady(Boolean(element));}, []);useEffect(() => {@@ -584,7 +567,7 @@ export const EditorPane = ({}if (isMobileViewport && !readOnly) {- if (mobileImeBridgeInputRef.current) {+ if (mobileTextAreaRef.current) {focusMobileInputTarget();return;}@@ -612,15 +595,6 @@ export const EditorPane = ({}}, [focusMobileInputTarget, isMobileViewport, memo?.id, mobileDefaultEditMemoId, onMobileDefaultEditConsumed, readOnly]);- useEffect(() => {- if (!useMobilePlainTextEditor || !mobileImeBridgeReady) {- return;- }-- const frame = window.requestAnimationFrame(() => focusMobileInputTarget());- return () => window.cancelAnimationFrame(frame);- }, [focusMobileInputTarget, mobileImeBridgeReady, useMobilePlainTextEditor]);-const insertImageFiles = useCallback((files: File[]) => {const currentMemo = memoRef.current;const currentEditor = editorRef.current;@@ -943,7 +917,7 @@ export const EditorPane = ({}, [recordMobileImeDebugEvent]);useEffect(() => {- if (!useMobilePlainTextEditor || !mobileImeBridgeReady) {+ if (!useMobilePlainTextEditor) {return;}@@ -1026,9 +1000,6 @@ export const EditorPane = ({setTagsText("");setMobilePlainText("");setMobilePlainTextElementValue(mobileTextAreaRef.current, "");- if (mobileImeBridgeInputRef.current) {- mobileImeBridgeInputRef.current.value = "";- }setSaveState("idle");if (isEditorReady(currentEditor)) {currentEditor.commands.clearContent();@@ -1073,9 +1044,6 @@ export const EditorPane = ({setTagsText(nextTagsText);setMobilePlainText(nextMarkdown);setMobilePlainTextElementValue(mobileTextAreaRef.current, nextMarkdown);- if (mobileImeBridgeInputRef.current) {- mobileImeBridgeInputRef.current.value = "";- }if (isEditorReady(currentEditor)) {currentEditor.commands.setContent(nextContent);@@ -1318,121 +1286,6 @@ export const EditorPane = ({markMobilePlainTextDirtyRef.current = markMobilePlainTextDirty;}, [markMobilePlainTextDirty]);- useEffect(() => {- if (!useMobilePlainTextEditor) {- return;- }-- const bridgeInput = mobileImeBridgeInputRef.current;- if (!bridgeInput) {- return;- }-- const updateBodyText = (nextValue: string) => {- setMobilePlainText(nextValue);- setMobilePlainTextElementValue(mobileTextAreaRef.current, nextValue);- markMobilePlainTextDirtyRef.current();- };- const appendToBodyText = (value: string) => {- if (!value) {- return;- }-- updateBodyText(`${getMobilePlainTextElementValue(mobileTextAreaRef.current)}${value}`);- };- const deleteLastBodyCharacter = () => {- const currentValue = getMobilePlainTextElementValue(mobileTextAreaRef.current);- if (!currentValue) {- return;- }-- updateBodyText(Array.from(currentValue).slice(0, -1).join(""));- };- const commitBridgeInputValue = () => {- const value = bridgeInput.value;- if (!value) {- return;- }-- appendToBodyText(value);- bridgeInput.value = "";- };- const recordBridgeEvent = (event: Event) => {- mobileImeDebugRecorderRef.current(`bridge-${event.type}`, event);- };- const handleBridgeBeforeInput = (event: Event) => {- recordBridgeEvent(event);- const inputEvent = event as InputEvent;-- if (inputEvent.inputType === "insertLineBreak") {- if (event.cancelable) {- event.preventDefault();- }- appendToBodyText("\n");- bridgeInput.value = "";- return;- }-- if (inputEvent.inputType === "deleteContentBackward" && !bridgeInput.value) {- if (event.cancelable) {- event.preventDefault();- }- deleteLastBodyCharacter();- }- };- const handleBridgeInput = (event: Event) => {- recordBridgeEvent(event);- if (!mobileImeBridgeComposingRef.current) {- commitBridgeInputValue();- }- };- const handleBridgeCompositionStart = (event: Event) => {- mobileImeBridgeComposingRef.current = true;- recordBridgeEvent(event);- };- const handleBridgeCompositionEnd = (event: Event) => {- mobileImeBridgeComposingRef.current = false;- recordBridgeEvent(event);- commitBridgeInputValue();- };- const handleBridgeKeyDown = (event: Event) => {- recordBridgeEvent(event);- const keyboardEvent = event as KeyboardEvent;-- if (keyboardEvent.key === "Enter") {- event.preventDefault();- appendToBodyText("\n");- bridgeInput.value = "";- return;- }-- if (keyboardEvent.key === "Backspace" && !bridgeInput.value) {- deleteLastBodyCharacter();- }- };-- bridgeInput.addEventListener("focus", recordBridgeEvent);- bridgeInput.addEventListener("blur", recordBridgeEvent);- bridgeInput.addEventListener("click", recordBridgeEvent);- bridgeInput.addEventListener("beforeinput", handleBridgeBeforeInput);- bridgeInput.addEventListener("input", handleBridgeInput);- bridgeInput.addEventListener("compositionstart", handleBridgeCompositionStart);- bridgeInput.addEventListener("compositionend", handleBridgeCompositionEnd);- bridgeInput.addEventListener("keydown", handleBridgeKeyDown);- mobileImeDebugRecorderRef.current("bridge-listeners-ready");-- return () => {- bridgeInput.removeEventListener("focus", recordBridgeEvent);- bridgeInput.removeEventListener("blur", recordBridgeEvent);- bridgeInput.removeEventListener("click", recordBridgeEvent);- bridgeInput.removeEventListener("beforeinput", handleBridgeBeforeInput);- bridgeInput.removeEventListener("input", handleBridgeInput);- bridgeInput.removeEventListener("compositionstart", handleBridgeCompositionStart);- bridgeInput.removeEventListener("compositionend", handleBridgeCompositionEnd);- bridgeInput.removeEventListener("keydown", handleBridgeKeyDown);- };- }, [mobileImeBridgeReady, useMobilePlainTextEditor]);-useEffect(() => {if (!useMobilePlainTextEditor) {return;@@ -1585,8 +1438,7 @@ export const EditorPane = ({? `${noteSearchMatches.length > 0 ? noteSearchIndex + 1 : 0}/${noteSearchMatches.length}`: "0/0";const mobileImeDebugEditorFocused =- typeof document !== "undefined" &&- (mobileTextAreaRef.current === document.activeElement || mobileImeBridgeInputRef.current === document.activeElement);+ typeof document !== "undefined" && mobileTextAreaRef.current === document.activeElement;const mobileImeDebugLogText = [`memoId=${memo.id}`,`mobile=${isMobileViewport}`,@@ -1596,7 +1448,6 @@ export const EditorPane = ({`editorFocused=${mobileImeDebugEditorFocused}`,`activeElement=${mobileImeDebugActiveElement}`,`valueLength=${getMobilePlainTextValue().length}`,- `bridgeValueLength=${mobileImeBridgeInputRef.current?.value.length ?? 0}`,`saveState=${saveState}`,...mobileImeDebugEvents.map((entry) =>`${entry.time} ${entry.event} active=${entry.activeElement} len=${entry.valueLength}` +@@ -1606,6 +1457,21 @@ export const EditorPane = ({),].join("\n");+ const handleMobilePromptInput = () => {+ const nextText = window.prompt("输入笔记内容");+ if (!nextText) {+ focusMobileInputTarget();+ return;+ }++ const currentText = getMobilePlainTextValue();+ const nextValue = `${currentText}${currentText ? "\n" : ""}${nextText}`;+ setMobilePlainText(nextValue);+ setMobilePlainTextElementValue(mobileTextAreaRef.current, nextValue);+ markMobilePlainTextDirty();+ window.requestAnimationFrame(() => focusMobileInputTarget());+ };+const updateMemoNotebook = (notebookId: string, sourceMemo: MemoDetail = memoRef.current ?? memo) => {if (effectiveReadOnly || notebookId === sourceMemo.notebookId || notebookUpdatePending) {setMobileNotebookSheetOpen(false);@@ -2057,36 +1923,24 @@ export const EditorPane = ({<div className="edgeever-editor min-h-0 flex-1 overflow-y-auto bg-white">{useMobilePlainTextEditor ? (- <div className="flex min-h-full w-full flex-col bg-white">- <input- ref={bindMobileImeBridgeInput}- type="text"- autoCapitalize="sentences"- autoComplete="off"- autoCorrect="on"- enterKeyHint="enter"- inputMode="text"- spellCheck- data-edgeever-mobile-ime-bridge="true"- aria-label="笔记正文输入"- className="block w-full border-0 bg-white px-4 py-3 text-base leading-7 text-slate-900 outline-none placeholder:text-slate-400 sm:px-7"- placeholder={mobilePlainText ? "继续输入..." : "开始记录..."}- />- <div- ref={mobileTextAreaRef}- role="textbox"- tabIndex={-1}- aria-label="笔记正文"- aria-multiline="true"- data-edgeever-mobile-editor="plain-content-display"- className="block min-h-[12rem] flex-1 whitespace-pre-wrap break-words bg-white px-4 pb-6 pt-1 text-base leading-7 text-slate-900 outline-none sm:px-7"- style={{ WebkitUserSelect: "text", userSelect: "text", caretColor: "auto" }}- onPointerDown={() => window.requestAnimationFrame(() => focusMobileInputTarget())}- onClick={focusMobileInputTarget}- >- {mobilePlainText}- </div>- </div>+ <textarea+ ref={(element) => {+ mobileTextAreaRef.current = element;+ }}+ defaultValue={mobilePlainText}+ autoCapitalize="sentences"+ autoComplete="on"+ autoCorrect="on"+ enterKeyHint="enter"+ inputMode="text"+ name="memo-body"+ spellCheck+ data-edgeever-mobile-editor="plain-textarea"+ aria-label="笔记正文"+ className="block min-h-full w-full resize-none border-0 bg-white px-4 py-3 text-base leading-7 text-slate-900 outline-none placeholder:text-slate-400 sm:px-7"+ placeholder="开始记录..."+ style={{ WebkitUserSelect: "text", userSelect: "text", caretColor: "auto" }}+ />) : (<EditorContent editor={editor} />)}@@ -2102,6 +1956,13 @@ export const EditorPane = ({>IME 诊断:{mobileImeDebugEditorFocused ? "正文已聚焦" : "正文未聚焦"} · len {getMobilePlainTextValue().length}</button>+ <button+ className="rounded border border-amber-300 bg-white px-2 py-1 font-medium text-slate-700"+ type="button"+ onClick={handleMobilePromptInput}+ >+ 输入+ </button><buttonclassName="rounded border border-amber-300 bg-white px-2 py-1 font-medium text-slate-700"type="button"