Skip to content

Commit a98c47c

Browse files
committed
refactor: use size, fix watcher
1 parent 3cded68 commit a98c47c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/components/VueCommand.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import last from 'lodash.last'
105105
import eq from 'lodash.eq'
106106
import nth from 'lodash.nth'
107107
import lt from 'lodash.lt'
108+
import size from 'lodash.size'
108109
109110
const props = defineProps({
110111
commands: {
@@ -265,11 +266,11 @@ const programs = computed(() => {
265266
const shouldShowHistoryEntry = computed(() => {
266267
return index => or(
267268
!local.isFullscreen,
268-
and(local.isFullscreen, eq(index, local.history.length - 1))
269+
and(local.isFullscreen, eq(index, size(local.history) - 1))
269270
)
270271
})
271272
const shouldBeFullscreen = computed(() => {
272-
return index => and(local.isFullscreen, eq(index, local.history.length - 1))
273+
return index => and(local.isFullscreen, eq(index, size(local.history) - 1))
273274
})
274275
275276
// Removes and adds the dispatched query to enforce the quries first position

src/components/VueCommandQuery.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const local = reactive({
9191
// and parsed query if there are more than two arguments
9292
const autocompleteQuery = async () => {
9393
const query = local.query
94+
9495
// An empty query shall be never autocompleted
9596
if (isEmpty(query)) {
9697
return
@@ -121,7 +122,7 @@ const autocompleteQuery = async () => {
121122
const program = head(commands)
122123
if (and(
123124
// Check if query expects autocomplete
124-
lt(program.length, size(trimStart(query))),
125+
lt(size(program), size(trimStart(query))),
125126
// Check if user provided options resolver
126127
isFunction(optionsResolver), isFunction(parser))
127128
) {
@@ -130,7 +131,7 @@ const autocompleteQuery = async () => {
130131
}
131132
132133
// If query has white spaces at the end, ignore
133-
if (gt(program.length, size(trimStart(query)))) {
134+
if (gt(size(program), size(trimStart(query)))) {
134135
setQuery(program)
135136
}
136137
@@ -200,11 +201,12 @@ const unwatchTerminalQuery = watch(
200201
local.query = query
201202
}
202203
)
203-
const unwatchIsDisabled = watch(isOutdated, () => {
204+
// Free resources if query is outdated/inactive
205+
const unwatchIsOutdated = watch(isOutdated, () => {
204206
unwatchTerminalQuery()
205207
unwatchLocalQuery()
206208
unwatchTerminalCursorPosition()
207-
unwatchIsDisabled()
209+
unwatchIsOutdated()
208210
placeholder.value = ''
209211
})
210212

src/utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// These are helpers for the package
2+
13
export const and = (x, y) => {
24
return x && y
35
}

0 commit comments

Comments
 (0)