Skip to content

Commit 2e45b71

Browse files
authored
Merge pull request #115 from arduino/feature/remember-scroll-position
Feature/remember scroll position
2 parents fc63ae5 + b868efe commit 2e45b71

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

ui/arduino/views/components/elements/editor.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,43 @@ class CodeMirrorEditor extends Component {
33
super()
44
this.editor = null
55
this.content = '# empty file'
6+
this.scrollTop = 0
67
}
78

9+
createElement(content) {
10+
if (content) this.content = content
11+
return html`<div id="code-editor"></div>`
12+
}
13+
14+
815
load(el) {
916
const onCodeChange = (update) => {
10-
// console.log('code change', this.content)
1117
this.content = update.state.doc.toString()
1218
this.onChange()
1319
}
1420
this.editor = createEditor(this.content, el, onCodeChange)
15-
}
1621

17-
createElement(content) {
18-
if (content) this.content = content
19-
return html`<div id="code-editor"></div>`
22+
setTimeout(() => {
23+
this.editor.scrollDOM.addEventListener('scroll', this.updateScrollPosition.bind(this))
24+
this.editor.scrollDOM.scrollTo({
25+
top: this.scrollTop,
26+
left: 0
27+
})
28+
}, 10)
2029
}
2130

2231
update() {
2332
return false
2433
}
2534

35+
unload() {
36+
this.editor.scrollDOM.removeEventListener('scroll', this.updateScrollPosition)
37+
}
38+
39+
updateScrollPosition(e) {
40+
this.scrollTop = e.target.scrollTop
41+
}
42+
2643
onChange() {
2744
return false
2845
}

ui/arduino/views/components/elements/tab.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function Tab(args) {
5757
}
5858

5959
function selectTab(e) {
60-
if(e.target.tagName === 'BUTTON' || e.target.tagName === 'IMG') return
60+
if(e.target.classList.contains('close-tab')) return
6161
onSelectTab(e)
6262
}
6363

@@ -71,9 +71,9 @@ function Tab(args) {
7171
<div class="text">
7272
${hasChanges ? '*' : ''} ${text}
7373
</div>
74-
<div class="options">
75-
<button onclick=${onCloseTab}>
76-
<img class="icon" src="media/close.svg" />
74+
<div class="options close-tab">
75+
<button class="close-tab" onclick=${onCloseTab}>
76+
<img class="close-tab icon" src="media/close.svg" />
7777
</button>
7878
</div>
7979
</div>

0 commit comments

Comments
 (0)