Skip to content

Commit 9161170

Browse files
authored
feat(review): ability to resize review card editor (#66)
1 parent 1a5e48b commit 9161170

File tree

4 files changed

+66
-144
lines changed

4 files changed

+66
-144
lines changed

src/app/src/components/content/ContentCardReview.vue

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { DraftItem, DatabaseItem, DatabasePageItem } from '../../types'
33
import type { PropType } from 'vue'
4-
import { ref, computed, nextTick, watch } from 'vue'
4+
import { ref, computed, nextTick, watch, onMounted, onUnmounted } from 'vue'
55
import { DraftStatus, ContentFileExtension } from '../../types'
66
import { getFileExtension } from '../../utils/file'
77
import { generateContentFromDocument, isEqual } from '../../utils/content'
@@ -25,6 +25,46 @@ const isLoadingContent = ref(false)
2525
const isOpen = ref(false)
2626
const isAutomaticFormattingDetected = ref(false)
2727
28+
const height = ref(200)
29+
const isResizing = ref(false)
30+
const resizeStartY = ref(0)
31+
const resizeStartHeight = ref(0)
32+
const MIN_HEIGHT = 200
33+
const MAX_HEIGHT = 600
34+
35+
function startResize(event: MouseEvent) {
36+
event.preventDefault()
37+
isResizing.value = true
38+
resizeStartY.value = event.clientY
39+
resizeStartHeight.value = height.value
40+
}
41+
42+
function handleMouseMove(event: MouseEvent) {
43+
if (!isResizing.value) return
44+
45+
event.preventDefault()
46+
const deltaY = event.clientY - resizeStartY.value
47+
const newHeight = resizeStartHeight.value + deltaY
48+
49+
// Limit to constraints
50+
height.value = Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, newHeight))
51+
}
52+
53+
function handleMouseUp() {
54+
if (!isResizing.value) return
55+
isResizing.value = false
56+
}
57+
58+
onMounted(() => {
59+
document.addEventListener('mousemove', handleMouseMove)
60+
document.addEventListener('mouseup', handleMouseUp)
61+
})
62+
63+
onUnmounted(() => {
64+
document.removeEventListener('mousemove', handleMouseMove)
65+
document.removeEventListener('mouseup', handleMouseUp)
66+
})
67+
2868
const language = computed(() => {
2969
const ext = getFileExtension(props.draftItem.fsPath)
3070
switch (ext) {
@@ -65,7 +105,6 @@ async function initializeEditor() {
65105
language: language.value,
66106
colorMode: ui.colorMode,
67107
editorOptions: {
68-
// hide unchanged regions
69108
hideUnchangedRegions: {
70109
enabled: true,
71110
},
@@ -91,7 +130,10 @@ async function initializeEditor() {
91130
:draft-item="draftItem"
92131
>
93132
<template #open>
94-
<div class="bg-elevated h-[200px]">
133+
<div
134+
class="bg-elevated relative"
135+
:style="{ height: `${height}px` }"
136+
>
95137
<div
96138
v-if="isLoadingContent"
97139
class="p-4 flex items-center justify-center h-full"
@@ -116,6 +158,18 @@ async function initializeEditor() {
116158
class="w-full h-full"
117159
/>
118160
</div>
161+
162+
<!-- Resize handle -->
163+
<div
164+
class="absolute bottom-0 left-0 right-0 h-1 cursor-row-resize bg-transparent hover:bg-accented transition-colors duration-200 group"
165+
:class="{ 'bg-accented': isResizing }"
166+
@mousedown="startResize"
167+
>
168+
<div
169+
class="absolute bottom-0 left-1/2 transform -translate-x-1/2 h-1 w-8 bg-inverted rounded-t opacity-0 group-hover:opacity-100 transition-opacity duration-200"
170+
:class="{ 'opacity-100': isResizing }"
171+
/>
172+
</div>
119173
</div>
120174
</template>
121175
</ItemCardReview>

src/app/src/composables/useMonaco.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ export function useMonaco(target: Ref<HTMLElement | undefined>, options: UseMona
4747
lineNumbers: 'off',
4848
readOnly: options.readOnly ?? false,
4949
wordWrap: 'on',
50+
automaticLayout: true,
5051
overflowWidgetsDomNode: monacoPortal,
51-
scrollbar: options.readOnly
52-
? {
53-
vertical: 'hidden',
54-
horizontal: 'hidden',
55-
handleMouseWheel: false,
56-
}
57-
: undefined,
5852
...options.editorOptions,
5953
})
6054

src/app/src/composables/useMonacoDiff.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { watch, unref, type Ref } from 'vue'
1+
import { watch, unref, type Ref, shallowRef } from 'vue'
22
import type { editor as Editor } from 'modern-monaco/editor-core'
33
import { setupMonaco } from '../utils/monaco/index'
44

@@ -11,7 +11,7 @@ export interface UseMonacoDiffOptions {
1111
}
1212

1313
export function useMonacoDiff(target: Ref, options: UseMonacoDiffOptions) {
14-
let editor: Editor.IStandaloneDiffEditor | null = null
14+
const editor = shallowRef<Editor.IStandaloneDiffEditor | null>(null)
1515
let isInitialized = false
1616

1717
const getTheme = (mode: 'light' | 'dark' = 'dark') => {
@@ -25,7 +25,7 @@ export function useMonacoDiff(target: Ref, options: UseMonacoDiffOptions) {
2525
const monaco = await setupMonaco()
2626
const colorMode = unref(options.colorMode) || 'dark'
2727

28-
editor = monaco.createDiffEditor(el, {
28+
editor.value = monaco.createDiffEditor(el, {
2929
theme: getTheme(colorMode),
3030
lineNumbers: 'off',
3131
readOnly: true,
@@ -37,15 +37,14 @@ export function useMonacoDiff(target: Ref, options: UseMonacoDiffOptions) {
3737
...options.editorOptions,
3838
})
3939

40-
// Watch for color mode changes
4140
watch(options.colorMode, (newMode) => {
42-
editor?.updateOptions({
41+
editor.value?.updateOptions({
4342
// @ts-expect-error -- theme is missing from IDiffEditorOptions
4443
theme: getTheme(newMode),
4544
})
4645
})
4746

48-
editor.setModel({
47+
editor.value.setModel({
4948
original: monaco.editor.createModel(options.original, options.language),
5049
modified: monaco.editor.createModel(options.modified, options.language),
5150
})
@@ -63,15 +62,15 @@ export function useMonacoDiff(target: Ref, options: UseMonacoDiffOptions) {
6362
}
6463
else if (!el && isInitialized) {
6564
isInitialized = false
66-
editor?.dispose()
67-
editor = null
65+
editor.value?.dispose()
66+
editor.value = null
6867
}
6968
},
7069
{ immediate: true, flush: 'post' },
7170
)
7271

7372
const setOptions = (opts: Editor.IStandaloneDiffEditorConstructionOptions) => {
74-
editor?.updateOptions(opts)
73+
editor.value?.updateOptions(opts)
7574
}
7675

7776
return {

src/app/src/composables/useMonacoMinimal.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)