138 lines
4.1 KiB
TypeScript
138 lines
4.1 KiB
TypeScript
// Metro module 11489 (f11490).
|
|
import { useState, useEffect, useCallback } from "react";
|
|
import { WHITESPACE_RE } from "../../../Constants";
|
|
import { isUnbrokenRun, isWhitespaceSeparatingBoundary } from "./AutocompleteUtils";
|
|
const search = {
|
|
kind: "idle"
|
|
};
|
|
let c7826_6 = {
|
|
search,
|
|
cleanupAnchor: null
|
|
};
|
|
export default function useMentionAnchor(a0, a1, a2, a3, a4) {
|
|
let r48, r72;
|
|
let c18889_0 = a0;
|
|
const [state, setState] = useState(c7826_6);
|
|
const { cleanupAnchor, search: search2 } = state;
|
|
const r35 = search2.kind !== "idle" ? search2.anchor : null;
|
|
const r36 = a3 ? r35 != null && r35 >= 0 && a0.startsWith(a4, r35) && a1 >= r35 + a4.length && isUnbrokenRun(a0, r35 + a4.length, a1) : a3;
|
|
const anchor2 = r36 ? r35 : null;
|
|
if (a3) {
|
|
const { search: search3, cleanupAnchor: cleanupAnchor2 } = state;
|
|
const kind = search3.kind;
|
|
if (kind === "idle") {
|
|
const r74 = a0.lastIndexOf(a4, a1);
|
|
const anchor3 = r74 !== -1 ? isWhitespaceSeparatingBoundary(a0, r74) ? r74 != null && r74 >= 0 && a0.startsWith(a4, r74) && a1 >= r74 + a4.length && isUnbrokenRun(a0, r74 + a4.length, a1) ? r74 : null : null : null;
|
|
r48 = anchor3 != null ? {
|
|
search: {
|
|
kind: "pending",
|
|
anchor: anchor3,
|
|
seenText: null
|
|
},
|
|
cleanupAnchor: null
|
|
} : {
|
|
search,
|
|
cleanupAnchor: a0.includes(a4) ? cleanupAnchor2 : null
|
|
};
|
|
} else if (kind === "active") {
|
|
const r67 = {
|
|
search: null,
|
|
cleanupAnchor: null
|
|
};
|
|
if (r36) {
|
|
r67.search = search3;
|
|
r72 = r67;
|
|
} else {
|
|
r67.search = search;
|
|
r67.cleanupAnchor = a0.includes(a4) ? search3.anchor : null;
|
|
r72 = r67;
|
|
}
|
|
r48 = r72;
|
|
} else {
|
|
r48 = void 0;
|
|
if (kind === "pending") {
|
|
const { anchor, seenText } = search3;
|
|
r48 = r36 ? {
|
|
search: {
|
|
kind: "active",
|
|
anchor
|
|
},
|
|
cleanupAnchor: cleanupAnchor2
|
|
} : a0.startsWith(a4, anchor) ? {
|
|
search: {
|
|
kind: "pending",
|
|
anchor,
|
|
seenText: null
|
|
},
|
|
cleanupAnchor: cleanupAnchor2
|
|
} : anchor > a0.length ? {
|
|
search,
|
|
cleanupAnchor: cleanupAnchor2
|
|
} : seenText == null ? {
|
|
search: {
|
|
kind: "pending",
|
|
anchor,
|
|
seenText: a0
|
|
},
|
|
cleanupAnchor: cleanupAnchor2
|
|
} : seenText !== a0 ? {
|
|
search,
|
|
cleanupAnchor: cleanupAnchor2
|
|
} : state;
|
|
}
|
|
}
|
|
} else {
|
|
r48 = {
|
|
search,
|
|
cleanupAnchor: null
|
|
};
|
|
}
|
|
let r2 = state.cleanupAnchor === r48.cleanupAnchor;
|
|
if (r2) {
|
|
const search4 = state.search;
|
|
const search5 = r48.search;
|
|
r2 = search4.kind === search5.kind && (search4.kind === "idle" || (search4.kind === "active" ? search5.kind === "active" && search4.anchor === search5.anchor : search5.kind === "pending" && search4.anchor === search5.anchor && search4.seenText === search5.seenText));
|
|
}
|
|
if (!r2) {
|
|
setState(r48);
|
|
}
|
|
useEffect(() => {
|
|
if (cleanupAnchor != null) {
|
|
const location2 = c18889_0.startsWith(a4, cleanupAnchor) ? cleanupAnchor : c18889_0.indexOf(a4);
|
|
if (!(location2 < 0)) {
|
|
let length = c18889_0.slice(location2).search(WHITESPACE_RE);
|
|
if (length === -1) {
|
|
length = c18889_0.length - location2;
|
|
}
|
|
const current = a2.current;
|
|
const applicationCommandManager = a2.current.getApplicationCommandManager();
|
|
let editId = applicationCommandManager == null ? void 0 : applicationCommandManager.props.editId;
|
|
if (editId == null) {
|
|
editId = void 0;
|
|
}
|
|
current.replaceRange({
|
|
location: location2,
|
|
length,
|
|
text: "",
|
|
editId
|
|
});
|
|
}
|
|
}
|
|
}, [cleanupAnchor, a0, a4, a2]);
|
|
return {
|
|
anchor: anchor2,
|
|
beginSearch: useCallback((a0) => {
|
|
if (a3) {
|
|
setState({
|
|
search: {
|
|
kind: "pending",
|
|
anchor: a0,
|
|
seenText: null
|
|
},
|
|
cleanupAnchor: null
|
|
});
|
|
}
|
|
}, [a3])
|
|
};
|
|
};
|