Skip to content

Commit

Permalink
fix: line highlighter hmr error
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 17, 2021
1 parent 5cde7a2 commit 020097a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/client/builtin/CodeHighlightController.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const props = defineProps({
},
})
const clicks = inject(injectionClicks)!
const elements = inject(injectionClicksElements)!
const disabled = inject(injectionClicksDisabled)!
const clicks = inject(injectionClicks)
const elements = inject(injectionClicksElements)
const disabled = inject(injectionClicksDisabled)
function makeid(length = 5) {
const result = []
Expand All @@ -44,18 +44,20 @@ const el = ref<HTMLDivElement>()
const vm = getCurrentInstance()
onMounted(() => {
const prev = props.at == null ? elements.value.length : props.at
const prev = props.at == null ? elements?.value.length : props.at
const index = computed(() => {
if (disabled.value)
if (disabled?.value)
return props.ranges.length - 1
return Math.min(Math.max(0, clicks.value - prev), props.ranges.length - 1)
return Math.min(Math.max(0, (clicks?.value || 0) - (prev || 0)), props.ranges.length - 1)
})
const rangeStr = computed(() => props.ranges[index.value] || '')
if (props.ranges.length >= 2 && !disabled.value) {
if (props.ranges.length >= 2 && !disabled?.value) {
const id = makeid()
const ids = range(props.ranges.length - 1).map(i => id + i)
elements.value.push(...ids)
onUnmounted(() => ids.forEach(i => remove(elements.value, i)), vm)
if (elements?.value) {
elements.value.push(...ids)
onUnmounted(() => ids.forEach(i => remove(elements.value, i)), vm)
}
}
watchEffect(() => {
Expand Down

0 comments on commit 020097a

Please sign in to comment.