|
8 | 8 | /* total - header - footer */
|
9 | 9 | height: calc(100% - 36px - 25px);
|
10 | 10 | display: flex;
|
| 11 | + &.resizing { |
| 12 | + cursor: ew-resize; |
| 13 | + .editor { |
| 14 | + cursor: ew-resize; |
| 15 | + } |
| 16 | + .preview { |
| 17 | + -webkit-user-select: none; |
| 18 | + } |
| 19 | + } |
11 | 20 | &.vim-mode {
|
12 | 21 | /* height - editorDialog */
|
13 | 22 | .CodeMirror-scroll {
|
|
17 | 26 | }
|
18 | 27 | }
|
19 | 28 | .editor, .preview {
|
| 29 | + min-width: 100px; |
20 | 30 | height: 100%;
|
21 |
| - flex: 1; |
22 | 31 | overflow: auto;
|
23 | 32 | }
|
24 | 33 | .editor {
|
25 | 34 | cursor: text;
|
| 35 | + overflow-x: hidden !important; |
| 36 | + position: relative; |
| 37 | + border-right: 1px solid #e3e3e3; |
26 | 38 | .editor-input {
|
27 | 39 | display: none;
|
28 | 40 | }
|
|
47 | 59 | tab-size: 2;
|
48 | 60 | }
|
49 | 61 | }
|
| 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 | + } |
50 | 71 | </style>
|
51 | 72 |
|
52 | 73 | <template>
|
53 | 74 | <div
|
54 | 75 | 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}]" |
56 | 77 | v-for="tab in tabs"
|
| 78 | + @mousemove="resizeMove($event, $index)" |
| 79 | + @mouseup="resizeEnd" |
| 80 | + @mouseleave="resizeEnd" |
57 | 81 | v-show="$index === currentTabIndex">
|
58 | 82 | <div
|
59 | 83 | class="editor"
|
60 | 84 | :class="{'focus-mode': tab.isFocusMode}"
|
| 85 | + :style="{ width: tab.split + '%' }" |
61 | 86 | v-show="currentTab && currentTab.writingMode !== 'preview'">
|
62 | 87 | <textarea class="editor-input" :id="'editor-' + $index">{{ tab.content }}</textarea>
|
| 88 | + <div class="resize-bar" @mousedown="resizeStart($event, $index)"></div> |
63 | 89 | </div>
|
64 | 90 | <div
|
65 | 91 | :class="'preview preview-' + $index"
|
| 92 | + :style="{ width: (100 - tab.split) + '%' }" |
66 | 93 | v-show="currentTab && currentTab.writingMode !== 'writing'">
|
67 | 94 | <div :class="'markdown-body markdown-body-' + $index">
|
68 | 95 | {{{ tab.html }}}
|
|
114 | 141 | },
|
115 | 142 | data() {
|
116 | 143 | return {
|
117 |
| - isMac |
| 144 | + isMac, |
| 145 | + resizing: false |
118 | 146 | }
|
119 | 147 | },
|
120 | 148 | created() {
|
|
252 | 280 | writingMode: 'default',
|
253 | 281 | isVimMode: false,
|
254 | 282 | pdf: '',
|
255 |
| - rename: false |
| 283 | + rename: false, |
| 284 | + split: 50 |
256 | 285 | })
|
257 | 286 |
|
258 | 287 | setTimeout(() => {
|
|
496 | 525 | }
|
497 | 526 | return false
|
498 | 527 | }
|
| 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() |
499 | 548 | }
|
500 | 549 | }
|
501 | 550 | }
|
|
0 commit comments