Skip to content

Commit 58a6cbb

Browse files
committed
feat: use acode quicktools search for terminal
1 parent 39b1734 commit 58a6cbb

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

src/components/terminal/terminal.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,29 @@ export default class TerminalComponent {
339339
/**
340340
* Search in terminal
341341
* @param {string} term - Search term
342-
* @param {object} options - Search options
342+
* @param {number} skip Number of search results to skip
343+
* @param {boolean} backward Whether to search backward
343344
*/
344-
search(term, options = {}) {
345+
search(term, skip, backward) {
345346
if (this.searchAddon) {
346-
return this.searchAddon.findNext(term, options);
347+
const searchOptions = {
348+
regex: appSettings.value.search.regExp || false,
349+
wholeWord: appSettings.value.search.wholeWord || false,
350+
caseSensitive: appSettings.value.search.caseSensitive || false,
351+
decorations: {
352+
matchBorder: "#FFA500",
353+
activeMatchBorder: "#FFFF00",
354+
},
355+
};
356+
if (!term) {
357+
return false;
358+
}
359+
360+
if (backward) {
361+
return this.searchAddon.findPrevious(term, searchOptions);
362+
} else {
363+
return this.searchAddon.findNext(term, searchOptions);
364+
}
347365
}
348366
return false;
349367
}

src/handlers/quickTools.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ function removeSearch() {
327327
$footer.removeAttribute("data-searching");
328328
$searchRow1.remove();
329329
$searchRow2.remove();
330+
const { activeFile } = editorManager;
331+
332+
// Check if current tab is a terminal
333+
if (
334+
activeFile &&
335+
activeFile.type === "terminal" &&
336+
activeFile.terminalComponent
337+
) {
338+
activeFile.terminalComponent.searchAddon?.clearDecorations();
339+
activeFile.terminalComponent.searchAddon?.clearActiveDecoration();
340+
return;
341+
}
330342
focusEditor();
331343
}
332344

@@ -337,20 +349,44 @@ function removeSearch() {
337349
*/
338350
function find(skip, backward) {
339351
const { $searchInput } = quickTools;
340-
editorManager.editor.find($searchInput.value, {
341-
skipCurrent: skip,
342-
...appSettings.value.search,
343-
backwards: backward,
344-
});
352+
const { activeFile } = editorManager;
353+
354+
// Check if current tab is a terminal
355+
if (
356+
activeFile &&
357+
activeFile.type === "terminal" &&
358+
activeFile.terminalComponent
359+
) {
360+
activeFile.terminalComponent.search($searchInput.value, skip, backward);
361+
} else {
362+
// Use ACE editor search for regular files
363+
editorManager.editor.find($searchInput.value, {
364+
skipCurrent: skip,
365+
...appSettings.value.search,
366+
backwards: backward,
367+
});
368+
}
345369

346370
updateSearchState();
347371
}
348372

349373
function updateSearchState() {
350374
const MAX_COUNT = 999;
351-
const { editor } = editorManager;
375+
const { activeFile } = editorManager;
352376
const { $searchPos, $searchTotal } = quickTools;
353377

378+
// Check if current tab is a terminal
379+
if (activeFile && activeFile.type === "terminal") {
380+
// For terminal, we can't easily count all matches like in ACE editor
381+
// xterm search addon doesn't provide this information
382+
// So we just show a generic indicator
383+
$searchTotal.textContent = "?";
384+
$searchPos.textContent = "?";
385+
return;
386+
}
387+
388+
// Use ACE editor search state for regular files
389+
const { editor } = editorManager;
354390
let regex = editor.$search.$options.re;
355391
let all = 0;
356392
let before = 0;

0 commit comments

Comments
 (0)