Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remember scroll position #115

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions ui/arduino/views/components/elements/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,44 @@ class CodeMirrorEditor extends Component {
super()
this.editor = null
this.content = '# empty file'
this.scrollTop = 0
}

createElement(content) {
if (content) this.content = content
return html`<div id="code-editor"></div>`
}


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)
}

createElement(content) {
if (content) this.content = content
return html`<div id="code-editor"></div>`
setTimeout(() => {
this.editor.scrollDOM.addEventListener('scroll', this.updateScrollPosition.bind(this))
this.editor.scrollDOM.scrollTo({
top: this.scrollTop,
left: 0
})
}, 10)
}

update() {
return false
}

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

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

onChange() {
return false
}
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