|  | 
|  | 1 | +<template> | 
|  | 2 | +  <n-element :class="$style.position"> | 
|  | 3 | +    Ln {{ rowIndex + 1 }}{{ position ? `, ${position}` : '' }} | Row {{ currentCols }} / Max {{ maxCols }} | 
|  | 4 | +  </n-element> | 
|  | 5 | +</template> | 
|  | 6 | + | 
|  | 7 | +<script lang="ts" setup> | 
|  | 8 | +import { computed } from 'vue'; | 
|  | 9 | +import { NElement } from 'naive-ui'; | 
|  | 10 | +import { max } from 'radash'; | 
|  | 11 | +
 | 
|  | 12 | +import type { RDTMap } from '@/ast'; | 
|  | 13 | +import { useEditorStore } from '@/stores/editor'; | 
|  | 14 | +
 | 
|  | 15 | +const props = defineProps<{ | 
|  | 16 | +  map: RDTMap; | 
|  | 17 | +}>(); | 
|  | 18 | +
 | 
|  | 19 | +const editorStore = useEditorStore(); | 
|  | 20 | +
 | 
|  | 21 | +const rowIndex = computed(() => editorStore.selection?.row ?? 0); | 
|  | 22 | +
 | 
|  | 23 | +const position = computed(() => { | 
|  | 24 | +  const { selection } = editorStore; | 
|  | 25 | +  if (!selection) return undefined; | 
|  | 26 | +
 | 
|  | 27 | +  const row = props.map.rows[selection.row]; | 
|  | 28 | +  if (!row || row.kind !== 'row') return undefined; | 
|  | 29 | +
 | 
|  | 30 | +  const lInfo = row.lInfo.find(({ offset, length }) => | 
|  | 31 | +    selection.offset >= offset - row.offset && selection.offset <= offset - row.offset + length | 
|  | 32 | +  ); | 
|  | 33 | +  if (lInfo) { | 
|  | 34 | +    return `Left Info #${lInfo.column}`; | 
|  | 35 | +  } | 
|  | 36 | +
 | 
|  | 37 | +  const rInfo = row.rInfo.find(({ offset, length }) => | 
|  | 38 | +    selection.offset >= offset - row.offset && selection.offset <= offset - row.offset + length | 
|  | 39 | +  ); | 
|  | 40 | +  if (rInfo) { | 
|  | 41 | +    return `Right Info #${rInfo.column}`; | 
|  | 42 | +  } | 
|  | 43 | +
 | 
|  | 44 | +  const cell = row.cells.findIndex(({ offset, length }) => | 
|  | 45 | +    selection.offset >= offset - row.offset && selection.offset <= offset - row.offset + length | 
|  | 46 | +  ); | 
|  | 47 | +  if (cell != -1) { | 
|  | 48 | +    return `Col ${cell + 1}`; | 
|  | 49 | +  } | 
|  | 50 | +
 | 
|  | 51 | +  return undefined; | 
|  | 52 | +}); | 
|  | 53 | +
 | 
|  | 54 | +const currentCols = computed(() => { | 
|  | 55 | +  const row = props.map.rows[rowIndex.value]; | 
|  | 56 | +  if (!row || row.kind !== 'row') return 0; | 
|  | 57 | +  return row.cells.length; | 
|  | 58 | +}); | 
|  | 59 | +
 | 
|  | 60 | +const maxCols = computed(() => max(props.map.rows | 
|  | 61 | +  .filter((row) => row.kind == 'row') | 
|  | 62 | +  .map((row) => row.cells.length) | 
|  | 63 | +) || 1); | 
|  | 64 | +</script> | 
|  | 65 | + | 
|  | 66 | +<style lang="scss" module> | 
|  | 67 | +.position { | 
|  | 68 | +  font-size: var(--font-size-tiny); | 
|  | 69 | +  color: var(--text-color-1); | 
|  | 70 | +} | 
|  | 71 | +</style> | 
0 commit comments