Skip to content

Commit b06d063

Browse files
Perkovecegoist
authored andcommitted
Resize pane (#42)
* Resize pane #32 * Fix text selecting in preview pane * Fix lint * Set pane min-width
1 parent 74a4d17 commit b06d063

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

src/components/header.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
drag-enter="handleDragEnter"
139139
drag-leave="handleDragLeave"
140140
drag-end="handleDragEnd"
141-
v-on:mouseover="hoverTab($index)"
142-
v-on:mouseleave="unhoverTab($index)"
141+
@mouseover="hoverTab($index)"
142+
@mouseleave="unhoverTab($index)"
143143
v-drag-and-drop>
144144
<div :class="{'dragzone': dragging}"></div>
145145
<span class="tab-title" v-if="tab && !tab.rename">

src/components/main.vue

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
/* total - header - footer */
99
height: calc(100% - 36px - 25px);
1010
display: flex;
11+
&.resizing {
12+
cursor: ew-resize;
13+
.editor {
14+
cursor: ew-resize;
15+
}
16+
.preview {
17+
-webkit-user-select: none;
18+
}
19+
}
1120
&.vim-mode {
1221
/* height - editorDialog */
1322
.CodeMirror-scroll {
@@ -17,12 +26,15 @@
1726
}
1827
}
1928
.editor, .preview {
29+
min-width: 100px;
2030
height: 100%;
21-
flex: 1;
2231
overflow: auto;
2332
}
2433
.editor {
2534
cursor: text;
35+
overflow-x: hidden !important;
36+
position: relative;
37+
border-right: 1px solid #e3e3e3;
2638
.editor-input {
2739
display: none;
2840
}
@@ -47,22 +59,37 @@
4759
tab-size: 2;
4860
}
4961
}
62+
.resize-bar {
63+
position: absolute;
64+
z-index: 99;
65+
top: 0;
66+
bottom: 0;
67+
right: -5px;
68+
width: 10px;
69+
cursor: ew-resize;
70+
}
5071
</style>
5172

5273
<template>
5374
<div
5475
class="main tab-body"
55-
:class="['tab-body-' + $index, {'vim-mode': currentTab && currentTab.isVimMode}]"
76+
:class="['tab-body-' + $index, {'vim-mode': currentTab && currentTab.isVimMode, 'resizing': resizing}]"
5677
v-for="tab in tabs"
78+
@mousemove="resizeMove($event, $index)"
79+
@mouseup="resizeEnd"
80+
@mouseleave="resizeEnd"
5781
v-show="$index === currentTabIndex">
5882
<div
5983
class="editor"
6084
:class="{'focus-mode': tab.isFocusMode}"
85+
:style="{ width: tab.split + '%' }"
6186
v-show="currentTab && currentTab.writingMode !== 'preview'">
6287
<textarea class="editor-input" :id="'editor-' + $index">{{ tab.content }}</textarea>
88+
<div class="resize-bar" @mousedown="resizeStart($event, $index)"></div>
6389
</div>
6490
<div
6591
:class="'preview preview-' + $index"
92+
:style="{ width: (100 - tab.split) + '%' }"
6693
v-show="currentTab && currentTab.writingMode !== 'writing'">
6794
<div :class="'markdown-body markdown-body-' + $index">
6895
{{{ tab.html }}}
@@ -114,7 +141,8 @@
114141
},
115142
data() {
116143
return {
117-
isMac
144+
isMac,
145+
resizing: false
118146
}
119147
},
120148
created() {
@@ -252,7 +280,8 @@
252280
writingMode: 'default',
253281
isVimMode: false,
254282
pdf: '',
255-
rename: false
283+
rename: false,
284+
split: 50
256285
})
257286
258287
setTimeout(() => {
@@ -496,6 +525,26 @@
496525
}
497526
return false
498527
}
528+
},
529+
resizeStart(e, index) {
530+
this.resizing = true
531+
this.startX = e.pageX
532+
this.startSplit = this.tabs[index].split
533+
},
534+
resizeMove(e, index) {
535+
if (this.resizing) {
536+
const dx = e.pageX - this.startX
537+
const totalWidth = this.$el.parentNode.offsetWidth
538+
this.$store.dispatch('UPDATE_EDITOR_SPLIT', {
539+
index,
540+
split: this.startSplit + (dx / totalWidth * 100)
541+
})
542+
}
543+
},
544+
resizeEnd() {
545+
this.resizing = false
546+
this.editor.refresh()
547+
this.editor.focus()
499548
}
500549
}
501550
}

src/vuex/modules/editor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const mutations = {
8484
UPDATE_DRAGGING_STATUS(state, dragging) {
8585
state.draggingTab = dragging
8686
},
87+
UPDATE_EDITOR_SPLIT(state, {index, split}) {
88+
state.tabs[index].split = split
89+
},
8790
SET_EDITOR(state, {index, editor}) {
8891
state.currentTabIndex = index
8992
state.tabs[index].editor = editor

0 commit comments

Comments
 (0)