Skip to content

Commit

Permalink
Remember scroll position between tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
murilopolese committed Apr 18, 2024
1 parent fc63ae5 commit 8515dd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion ui/arduino/views/components/elements/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ class CodeMirrorEditor extends Component {
super()
this.editor = null
this.content = '# empty file'
this.scrollTop = 0
}

load(el) {
const onCodeChange = (update) => {
// console.log('code change', this.content)
this.content = update.state.doc.toString()
this.onChange()
}
this.editor = createEditor(this.content, el, onCodeChange)
this.editor.scrollDOM.addEventListener('scroll', this.updateScrollPosition.bind(this))
setTimeout(() => {
this.editor.scrollDOM.scrollTo({
top: this.scrollTop,
left: 0
})
}, 1)
}

updateScrollPosition(e) {
console.log(e.target.scrollTop)
this.scrollTop = e.target.scrollTop
}

unload() {
this.editor.scrollDOM.removeEventListener('scroll', this.updateScrollPosition)
}

createElement(content) {
Expand Down
8 changes: 4 additions & 4 deletions ui/arduino/views/components/elements/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Tab(args) {
}

function selectTab(e) {
if(e.target.tagName === 'BUTTON' || e.target.tagName === 'IMG') return
if(e.target.classList.contains('close-tab')) return
onSelectTab(e)
}

Expand All @@ -71,9 +71,9 @@ function Tab(args) {
<div class="text">
${hasChanges ? '*' : ''} ${text}
</div>
<div class="options">
<button onclick=${onCloseTab}>
<img class="icon" src="media/close.svg" />
<div class="options close-tab">
<button class="close-tab" onclick=${onCloseTab}>
<img class="close-tab icon" src="media/close.svg" />
</button>
</div>
</div>
Expand Down

0 comments on commit 8515dd5

Please sign in to comment.