refactor: update mention handling and improve role options

- Refactored MentionableTextarea to use a getter for trigger index, enhancing performance and avoiding stale closures.
- Updated PRESET_ROLES to include additional roles: architect, docs, auditor, and optimizer, expanding role selection options.
- Adjusted package.json build scripts to remove automatic publishing flags for a more streamlined build process.
This commit is contained in:
iliya 2026-03-03 00:11:31 +02:00
parent 8c80611788
commit 7206b231f0
4 changed files with 26 additions and 11 deletions

View file

@ -23,11 +23,11 @@
"prebuild": "tsx scripts/fetch-pricing-data.ts",
"build": "electron-vite build",
"dist": "electron-builder --mac --win --linux",
"dist:mac": "electron-builder --mac --publish always",
"dist:mac:arm64": "electron-builder --mac --arm64 --publish always",
"dist:mac:x64": "electron-builder --mac --x64 --publish always",
"dist:win": "electron-builder --win --publish always",
"dist:linux": "electron-builder --linux --publish always",
"dist:mac": "electron-builder --mac",
"dist:mac:arm64": "electron-builder --mac --arm64",
"dist:mac:x64": "electron-builder --mac --x64",
"dist:win": "electron-builder --win",
"dist:linux": "electron-builder --linux",
"preview": "electron-vite preview",
"typecheck": "tsc --noEmit",
"lint": "eslint src/",

View file

@ -254,7 +254,7 @@ export const MentionableTextarea = React.forwardRef<HTMLTextAreaElement, Mention
dropdownPosition,
selectSuggestion,
dismiss,
triggerIndex,
getTriggerIndex,
handleKeyDown: mentionHandleKeyDown,
handleChange: mentionHandleChange,
handleSelect: mentionHandleSelect,
@ -296,10 +296,11 @@ export const MentionableTextarea = React.forwardRef<HTMLTextAreaElement, Mention
const handleFileSelect = React.useCallback(
(s: MentionSuggestion) => {
const textarea = internalRef.current;
if (!textarea || triggerIndex < 0 || !s.filePath) return;
const triggerIdx = getTriggerIndex();
if (!textarea || triggerIdx < 0 || !s.filePath) return;
const replaceStart = triggerIndex;
const replaceEnd = triggerIndex + 1 + query.length;
const replaceStart = triggerIdx;
const replaceEnd = triggerIdx + 1 + query.length;
const before = value.slice(0, replaceStart);
const after = value.slice(replaceEnd);
@ -347,7 +348,7 @@ export const MentionableTextarea = React.forwardRef<HTMLTextAreaElement, Mention
});
}
},
[triggerIndex, query, value, chips, onValueChange, onFileChipInsert, onChipRemove, dismiss]
[getTriggerIndex, query, value, chips, onValueChange, onFileChipInsert, onChipRemove, dismiss]
);
// --- Merged selection handler ---

View file

@ -1,5 +1,14 @@
/** Preset role options shown in role selectors (Add Member, Create Team, Role Editor). */
export const PRESET_ROLES = ['reviewer', 'developer', 'qa', 'researcher'] as const;
export const PRESET_ROLES = [
'architect',
'reviewer',
'developer',
'qa',
'researcher',
'docs',
'auditor',
'optimizer',
] as const;
/** Sentinel value for "custom role" in select dropdowns. */
export const CUSTOM_ROLE = '__custom__';

View file

@ -29,6 +29,8 @@ interface UseMentionDetectionResult {
handleSelect: (e: React.SyntheticEvent<HTMLTextAreaElement>) => void;
/** Current @-trigger character position in text (-1 if no active trigger) */
triggerIndex: number;
/** Getter for trigger index — use at call time to avoid stale closure */
getTriggerIndex: () => number;
}
interface MentionTrigger {
@ -310,6 +312,8 @@ export function useMentionDetection({
[isOpen, filteredSuggestions, selectedIndex, selectSuggestion, dismiss]
);
const getTriggerIndex = useCallback(() => triggerIndexRef.current, []);
return {
isOpen,
query,
@ -323,5 +327,6 @@ export function useMentionDetection({
handleSelect,
// eslint-disable-next-line react-hooks/refs -- expose current trigger position to caller
triggerIndex: triggerIndexRef.current,
getTriggerIndex,
};
}