Skip to content

Commit 43b43f8

Browse files
committed
[vue3] feat 新增全部折叠和全部展开API: switchAllFoldState tzfun#92
1 parent ceb1778 commit 43b43f8

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/Terminal.vue

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,9 @@ onMounted(() => {
506506
return _getCommand()
507507
} else if (type === 'setCommand') {
508508
return _setCommand(options)
509-
} else {
509+
} else if (type === 'switchAllFoldState') {
510+
return _switchAllFoldState(options)
511+
}else {
510512
console.error(`Unsupported event type ${type} in instance ${getName()}`)
511513
}
512514
})
@@ -1548,6 +1550,25 @@ const _closeGroupFold = (group: MessageGroup) => {
15481550
}
15491551
}
15501552
1553+
const _enableFold = (group: MessageGroup) => {
1554+
return props.enableFold && group.tag !== 'init' && group.logs.length > 1 && group.logs[0].type === 'cmdLine'
1555+
}
1556+
1557+
const _switchAllFoldState = (fold: boolean) => {
1558+
let count = 0;
1559+
if (props.enableFold) {
1560+
for (let group of terminalLog.value) {
1561+
if (_enableFold(group) && group.fold !== fold) {
1562+
group.fold = fold
1563+
count++;
1564+
}
1565+
}
1566+
} else {
1567+
console.warn("Before using folding related functions, please set enable-fold to enable the folding function.")
1568+
}
1569+
return count
1570+
}
1571+
15511572
defineExpose({
15521573
pushMessage: _pushMessage,
15531574
fullscreen: _fullscreen,
@@ -1566,7 +1587,10 @@ defineExpose({
15661587
return api.textEditorOpen(getName(), options)
15671588
},
15681589
textEditorClose: _textEditorClose,
1569-
clearLog: _clearLog
1590+
clearLog: _clearLog,
1591+
getCommand: _getCommand,
1592+
setCommand: _setCommand,
1593+
switchAllFoldState: _switchAllFoldState
15701594
})
15711595
15721596
</script>
@@ -1598,7 +1622,7 @@ defineExpose({
15981622
:key="groupIdx"
15991623
:class="`t-log-box t-log-fold-container ${enableHoverStripe && group.logs.length > 1 ? 't-log-box-hover-script' : ''} ${group.fold ? 't-log-box-folded' : ''}`"
16001624
:style="`margin-top:${lineSpace}px;`">
1601-
<span v-if="enableFold && group.tag !== 'init' && group.logs.length > 1">
1625+
<span v-if="_enableFold(group)">
16021626
<span class="t-log-fold-icon t-log-fold-icon-active" v-if="group.fold" @click="_closeGroupFold(group)">+</span>
16031627
<span class="t-log-fold-icon" v-else @click="group.fold = true">-</span>
16041628
<span class="t-log-fold-line" v-if="!group.fold"/>

src/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ export class TerminalApi {
302302
setCommand(name: string, options?: any): string | any {
303303
return this.post(name, 'setCommand', options)
304304
}
305+
306+
switchAllFoldState(name: string, options :boolean): any {
307+
return this.post(name, 'switchAllFoldState', options)
308+
}
305309
}
306310

307311
export interface EditorSetting {

test/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ const onExecCmd = (key: string, command: Command, success: SuccessFunc, failed:
198198
} else if (key === 'doclear') {
199199
TerminalApi.clearLog(name)
200200
success()
201+
} else if (key === 'fold') {
202+
success(TerminalApi.switchAllFoldState(name, true).toString())
203+
} else if (key === 'unfold') {
204+
success(TerminalApi.switchAllFoldState(name, false).toString())
201205
} else {
202206
failed("Unknown command: " + key)
203207
}

0 commit comments

Comments
 (0)