Skip to content

Commit c327664

Browse files
committed
style: 将useFilter更名为更符合实际功能的useActiveContext
1 parent 50e900b commit c327664

11 files changed

Lines changed: 67 additions & 68 deletions

File tree

src/components/layout/SidebarRight.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
v-for="message in chunk.messages"
2121
:key="message.messageId"
2222
v-show="
23-
filterTool.selectedMessageIds.value.has(
23+
activeContext.selectedMessageIds.value.has(
2424
message.messageId,
2525
)
2626
"
@@ -184,28 +184,30 @@
184184

185185
<script setup lang="ts">
186186
import { computed } from 'vue';
187-
import { useFilter } from '@/composables/useFilter';
187+
import { useActiveContext } from '@/composables/useActiveContext';
188188
import { useLogStore } from '@/stores/logStore';
189189
import { useMessageEditorStore } from '@/stores/editorStore/messageStore';
190190
import { formatDate } from '@/utils/date';
191191
192-
const filterTool = useFilter();
192+
const activeContext = useActiveContext();
193193
const logStore = useLogStore();
194194
const messageEditorStore = useMessageEditorStore();
195195
const allChunks = computed(() => logStore.allChunks);
196196
197197
// updateMessage 需要 chunkId 才能准确定位
198198
const selectedItems = computed(() => {
199199
return logStore.allMessages
200-
.filter((msg) => filterTool.selectedMessageIds.value.has(msg.messageId))
200+
.filter((msg) =>
201+
activeContext.selectedMessageIds.value.has(msg.messageId),
202+
)
201203
.map((msg) => ({
202204
message: { ...msg },
203205
chunkId: msg.chunkId,
204206
}));
205207
});
206208
207209
const selectedMessageCount = computed(
208-
() => filterTool.selectedMessageIds.value.size,
210+
() => activeContext.selectedMessageIds.value.size,
209211
);
210212
211213
function updateField(

src/components/layout/StatusBar.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ import { computed } from 'vue';
7878
import { useLogStore } from '@/stores/logStore';
7979
import { useWindowStore } from '@/stores/windowStore';
8080
import { useStyleStore } from '@/stores/styleStore';
81-
import { useFilter } from '@/composables/useFilter';
81+
import { useActiveContext } from '@/composables/useActiveContext';
8282
import { matchesMessageFilter } from '@/editor/filter';
8383
8484
const logStore = useLogStore();
8585
const windowStore = useWindowStore();
8686
const styleStore = useStyleStore();
87-
const filterTool = useFilter();
87+
const activeContext = useActiveContext();
8888
8989
const activeChunk = computed(function () {
9090
if (
@@ -136,11 +136,11 @@ const currentDocumentName = computed(function () {
136136
});
137137
138138
const selectedCount = computed(function () {
139-
return filterTool.selectedMessagesCount.value;
139+
return activeContext.selectedMessagesCount.value;
140140
});
141141
142142
const selectedCustomRuleCount = computed(function () {
143-
const selectedMessages = filterTool.selectedMessages.value;
143+
const selectedMessages = activeContext.selectedMessages.value;
144144
const customRules = styleStore.customRules;
145145
146146
if (selectedMessages.length === 0 || customRules.length === 0) {
@@ -162,12 +162,12 @@ const selectedCustomRuleCount = computed(function () {
162162
});
163163
164164
const currentSelectedIndex = computed<number | null>(function () {
165-
if (filterTool.selectedMessageIds.value.size === 0) {
165+
if (activeContext.selectedMessageIds.value.size === 0) {
166166
return null;
167167
}
168168
169-
if (activeChunk.value && filterTool.lastSelectedMessageId.value) {
170-
const targetId = filterTool.lastSelectedMessageId.value;
169+
if (activeChunk.value && activeContext.lastSelectedMessageId.value) {
170+
const targetId = activeContext.lastSelectedMessageId.value;
171171
const msg = activeChunk.value.messages.find(function (message) {
172172
return message.messageId === targetId;
173173
});

src/components/layout/TopMenuBar.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ import { useStyleStore } from '@/stores/styleStore';
184184
import { useClipboardStore } from '@/stores/clipboardStore';
185185
import { useHistoryStore } from '@/stores/historyStore';
186186
import { useWindowStore } from '@/stores/windowStore';
187-
import { useFilter } from '@/composables/useFilter';
187+
import { useActiveContext } from '@/composables/useActiveContext';
188188
import { useFileImport } from '@/composables/useImporter';
189189
import { useProjectManager } from '@/composables/useProjectManager';
190190
import { useExport } from '@/composables/useExporter';
@@ -199,7 +199,7 @@ const clipboardStore = useClipboardStore();
199199
const historyStore = useHistoryStore();
200200
const windowStore = useWindowStore();
201201
202-
const filterTool = useFilter();
202+
const activeContext = useActiveContext();
203203
const { importAndApply } = useFileImport();
204204
const { exportAsText, exportAsHtml, exportAsDoc, exportAsDocx } = useExport();
205205
const projectManager = useProjectManager();
@@ -233,7 +233,7 @@ const hasWorkspaceState = computed(() => {
233233
logStore.documents.length > 0 ||
234234
styleStore.rules.length > 0 ||
235235
clipboardStore.copiedMessages.length > 0 ||
236-
filterTool.hasSelection.value ||
236+
activeContext.hasSelection.value ||
237237
historyStore.undoStack.length > 0 ||
238238
historyStore.redoStack.length > 0
239239
);
@@ -373,7 +373,7 @@ function handleClearAll() {
373373
logStore.clearData();
374374
styleStore.clearRules();
375375
clipboardStore.clearClipboard();
376-
filterTool.clearSelection();
376+
activeContext.clearSelection();
377377
historyStore.clearHistory();
378378
windowStore.setFocus('default');
379379
}

src/components/panels/ChunkListPanel.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
chunk.chunkId,
114114
// 选中判断
115115
'is-selected':
116-
filterTool.selectedChunkIds.value.has(
116+
activeContext.selectedChunkIds.value.has(
117117
chunk.chunkId,
118118
),
119119
}"
@@ -215,14 +215,14 @@ import { useLogStore } from '@/stores/logStore';
215215
import { useStyleStore } from '@/stores/styleStore';
216216
import { useWindowStore } from '@/stores/windowStore';
217217
import type { Chunk, LogDocument } from '@/types/log';
218-
import { useFilter } from '@/composables/useFilter';
218+
import { useActiveContext } from '@/composables/useActiveContext';
219219
220220
const logStore = useLogStore();
221221
const styleStore = useStyleStore();
222222
const windowStore = useWindowStore();
223223
const chunkEditorStore = useChunkEditorStore();
224224
const chunkDrag = useChunkDragDrop();
225-
const filterTool = useFilter('chunkList');
225+
const activeContext = useActiveContext('chunkList');
226226
227227
const editingDocId = ref('');
228228
const editingChunkId = ref('');
@@ -334,7 +334,7 @@ function handleMerge(currentChunkId: string, nextChunkId: string) {
334334
}
335335
336336
function handleChunkSelect(chunkId: string, event: MouseEvent) {
337-
filterTool.handleChunkClickSelection(event, chunkId);
337+
activeContext.handleChunkClickSelection(event, chunkId);
338338
339339
if (!event.ctrlKey && !event.metaKey && !event.shiftKey) {
340340
if (windowStore.isInSplitMode()) {
@@ -359,7 +359,7 @@ function handleChunkSelect(chunkId: string, event: MouseEvent) {
359359
}
360360
361361
function handleDelete(chunkId: string) {
362-
const { selectedChunkIds, clearSelection } = filterTool;
362+
const { selectedChunkIds, clearSelection } = activeContext;
363363
364364
const targets = selectedChunkIds.value.has(chunkId)
365365
? Array.from(selectedChunkIds.value)

src/components/panels/RuleEditorPanel.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@
214214
<label>
215215
选区快捷绑定
216216
<span
217-
v-if="activeSelection.hasSelection"
217+
v-if="activeContext.hasSelection"
218218
class="inline-hint"
219219
>
220220
已选
221-
{{ activeSelection.selectedMessagesCount }} 条
221+
{{ activeContext.selectedMessagesCount }} 条
222222
</span>
223223
</label>
224224
<div class="form-row two-col">
@@ -257,7 +257,7 @@ import { ChevronRight, Eye, EyeOff, Plus, Trash2 } from '@lucide/vue';
257257
import { ref, computed } from 'vue';
258258
import { useStyleStore } from '@/stores/styleStore';
259259
import { useLogStore } from '@/stores/logStore';
260-
import { useFilter } from '@/composables/useFilter';
260+
import { useActiveContext } from '@/composables/useActiveContext';
261261
import type { ColorRule } from '@/types/config';
262262
import type { MessageFilter } from '@/types/log';
263263
import { matchesMessageFilter } from '@/editor/filter';
@@ -270,7 +270,7 @@ const activeViewId = computed(() => {
270270
const view = windowStore.currentActiveView;
271271
return view.originalId || view.windowId;
272272
});
273-
const activeSelection = useFilter(activeViewId.value);
273+
const activeContext = useActiveContext(activeViewId.value);
274274
const expandedRules = ref<Set<string>>(new Set());
275275
276276
function toggleExpand(ruleId: string) {
@@ -360,7 +360,7 @@ function getAffectedMessageCount(rule: ColorRule) {
360360
}
361361
362362
function bindSelectedIds(rule: ColorRule) {
363-
const selectedMsgs = activeSelection.selectedMessages.value;
363+
const selectedMsgs = activeContext.selectedMessages.value;
364364
if (selectedMsgs.length === 0) return;
365365
366366
const targetIds = selectedMsgs.map((m) => m.messageId);

src/components/panels/SearchPanel.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
class="result-item"
171171
:class="{
172172
'is-selected':
173-
filterStore.selectedMessageIds.value.has(
173+
activeContext.selectedMessageIds.value.has(
174174
msg.messageId,
175175
),
176176
'is-active':
@@ -201,7 +201,7 @@
201201
<script setup lang="ts">
202202
import { FunnelIcon, FunnelXIcon, RefreshCcw } from '@lucide/vue';
203203
import { computed } from 'vue';
204-
import { useFilter } from '@/composables/useFilter';
204+
import { useActiveContext } from '@/composables/useActiveContext';
205205
import type { Message } from '@/types/log';
206206
import { formatDate } from '@/utils/date';
207207
import { useCommandDispatcher } from '@/composables/useCommandDispatcher';
@@ -211,7 +211,7 @@ import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller';
211211
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
212212
213213
const windowStore = useWindowStore();
214-
const filterStore = useFilter('search');
214+
const activeContext = useActiveContext('search');
215215
const searchStore = useSearchStore();
216216
const { dispatch } = useCommandDispatcher();
217217
@@ -228,7 +228,7 @@ const isCommandFilterValue = computed<string>({
228228
},
229229
});
230230
const jumpTarget = computed<Message | null>(() => {
231-
const selectedIds = filterStore.selectedMessageIds.value;
231+
const selectedIds = activeContext.selectedMessageIds.value;
232232
const selectedTarget = searchStore.searchResults.find((msg) =>
233233
selectedIds.has(msg.messageId),
234234
);

src/components/workspace/ChunkView.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
:chunk-id="currentChunkId"
6969
:index="index"
7070
:is-selected="
71-
filterTool.selectedMessageIds.value.has(
71+
activeContext.selectedMessageIds.value.has(
7272
msg.messageId,
7373
)
7474
"
@@ -111,7 +111,7 @@ import { computed, nextTick, ref, watch } from 'vue';
111111
import { useLogStore } from '@/stores/logStore';
112112
import { useUiStore } from '@/stores/uiStore';
113113
import { useStyleStore } from '@/stores/styleStore';
114-
import { useFilter } from '@/composables/useFilter';
114+
import { useActiveContext } from '@/composables/useActiveContext';
115115
import { useMessageDragDrop } from '@/composables/useDragDrop';
116116
import MessageItem from '@/components/common/MessageItem.vue';
117117
import { useMessageEditorStore } from '@/stores/editorStore/messageStore';
@@ -128,7 +128,7 @@ const props = defineProps<{
128128
}>();
129129
const effectiveWindowId = computed(() => props.windowId);
130130
const currentChunkId = computed(() => props.originalId);
131-
const filterTool = useFilter(effectiveWindowId.value);
131+
const activeContext = useActiveContext(effectiveWindowId.value);
132132
const dragDropTool = useMessageDragDrop();
133133
const dropIndicatorIndex = ref<number | null>(null);
134134
const uiStore = useUiStore();
@@ -298,14 +298,14 @@ function handleActionInsert(msg: Message, index: number) {
298298
}
299299
300300
function handleActionMerge(msg: Message) {
301-
const selectedIds = filterTool.selectedMessageIds.value;
301+
const selectedIds = activeContext.selectedMessageIds.value;
302302
if (selectedIds.has(msg.messageId) && selectedIds.size > 1) {
303303
messageEditorStore.mergeMessages(
304304
currentChunkId.value,
305305
Array.from(selectedIds),
306306
msg.messageId,
307307
);
308-
filterTool.clearMessageSelection();
308+
activeContext.clearMessageSelection();
309309
} else {
310310
messageEditorStore.mergeWithNextMessage(
311311
currentChunkId.value,
@@ -319,10 +319,10 @@ function handleActionSplit(msgId: string) {
319319
}
320320
321321
function handleActionDelete(msgId: string) {
322-
const selectedIds = filterTool.selectedMessageIds.value;
322+
const selectedIds = activeContext.selectedMessageIds.value;
323323
if (selectedIds.has(msgId)) {
324324
messageEditorStore.batchDeleteMessages(selectedIds);
325-
filterTool.clearMessageSelection();
325+
activeContext.clearMessageSelection();
326326
} else {
327327
messageEditorStore.deleteMessage(currentChunkId.value, msgId);
328328
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { useLogStore } from '@/stores/logStore';
55
import { useWindowStore } from '@/stores/windowStore';
66
import { useSelectionStore } from '@/stores/selectionStore';
77

8-
// 这个文件名是一个历史遗留问题,它只有10行是filter,实际上是数据/选择/窗口的胶水层
9-
// 它和fiter.ts的关系类似于java与javascript的关系
10-
// 也许正确的名字应该叫 useActiveSelection.ts
11-
// 暂时不改这里的接口,后面再单独分离
12-
13-
export function useFilter(ownerId?: string) {
8+
export function useActiveContext(ownerId?: string) {
149
const logStore = useLogStore();
1510
const windowStore = useWindowStore();
1611
const selectionStore = useSelectionStore();

0 commit comments

Comments
 (0)