-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from lukashornych/dev
feat(#70): codemirror status bar with selection info and spaces info
- Loading branch information
Showing
4 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script setup lang="ts"> | ||
/** | ||
* Render the status bar of a single editor with info like selection, spaces, and so on. | ||
*/ | ||
import { EditorState } from '@codemirror/state' | ||
import CodemirrorFullStatusBarSelection from '@/components/base/CodemirrorFullStatusBarSelection.vue' | ||
const props = defineProps<{ | ||
state?: EditorState | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div v-if="state" class="status-bar"> | ||
<span v-if="state.selection.ranges.length > 1"> | ||
{{ state.selection.ranges.length }} selections | ||
</span> | ||
<span v-else-if="state.selection.ranges.length === 1"> | ||
<CodemirrorFullStatusBarSelection :doc="state.doc" :selection-range="state.selection.ranges[0]" /> | ||
</span> | ||
|
||
<span class="text-no-wrap"> | ||
{{state.tabSize}} spaces | ||
</span> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.status-bar { | ||
height: 2rem; | ||
display: flex; | ||
column-gap: 1rem; | ||
align-items: center; | ||
padding: 0 0.5rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script setup lang="ts"> | ||
/** | ||
* Render detailed info about the current text selection. | ||
*/ | ||
import { Text, SelectionRange, Line } from '@codemirror/state' | ||
import { computed } from 'vue' | ||
const props = defineProps<{ | ||
doc: Text, | ||
selectionRange: SelectionRange | ||
}>() | ||
const headLine = computed<Line>(() => { | ||
return props.doc.lineAt(props.selectionRange.head) | ||
}) | ||
const anchorLine = computed<Line>(() => { | ||
return props.doc.lineAt(props.selectionRange.anchor) | ||
}) | ||
const headPositionInLine = computed<number>(() => { | ||
return props.selectionRange.head - headLine.value.from + 1 | ||
}) | ||
const selectedCharsCount = computed<number>(() => { | ||
if (props.selectionRange.empty) { | ||
return 0 | ||
} | ||
return Math.abs(props.selectionRange.anchor - props.selectionRange.head) | ||
}) | ||
const selectedLinesCount = computed<number>(() => { | ||
if (props.selectionRange.empty) { | ||
return 0 | ||
} | ||
return Math.abs(anchorLine.value.number - headLine.value.number) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<span class="text-no-wrap"> | ||
Ln {{ headLine.number }}, Col {{ headPositionInLine }} | ||
<template v-if="!selectionRange.empty"> | ||
({{ selectedCharsCount }} chars<template v-if="selectedLinesCount">, {{ selectedLinesCount }} line breaks</template>) | ||
</template> | ||
</span> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters