refactor: declarative context-menu registry; named selection threshold
CONTEXT_MENU_ENTRIES maps every menu id to {action, style, parentId,
title}, replacing the split('-') id parsing that only worked because no
name contained a hyphen. Foreign menu ids are now ignored explicitly.
Parity pinned by tests enumerating all 30 previous ids. The 10-char
toolbar trigger threshold is now the named MIN_SELECTION_LENGTH.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { defineContentScript } from 'wxt/utils/define-content-script';
|
||||
import { isExtensionValid, safeSendMessage } from '@lib/messaging';
|
||||
import { WRITING_STYLES } from '@lib/actions';
|
||||
import { MIN_SELECTION_LENGTH, WRITING_STYLES } from '@lib/actions';
|
||||
|
||||
export default defineContentScript({
|
||||
matches: ['<all_urls>'],
|
||||
@@ -48,7 +48,7 @@ export default defineContentScript({
|
||||
const end = el.selectionEnd ?? -1;
|
||||
if (end - start >= 2) {
|
||||
const text = el.value.substring(start, end).trim();
|
||||
if (text.length > 10) {
|
||||
if (text.length >= MIN_SELECTION_LENGTH) {
|
||||
selectedText = text;
|
||||
storedStart = start;
|
||||
storedEnd = end;
|
||||
@@ -64,7 +64,7 @@ export default defineContentScript({
|
||||
const sel = window.getSelection();
|
||||
if (sel && sel.rangeCount > 0) {
|
||||
const text = sel.toString().trim();
|
||||
if (text.length > 10) {
|
||||
if (text.length >= MIN_SELECTION_LENGTH) {
|
||||
selectedText = text;
|
||||
storedRange = sel.getRangeAt(0).cloneRange(); // CLONE — selection will be lost later
|
||||
storedElement = null;
|
||||
|
||||
Reference in New Issue
Block a user