Skip to content

Commit

Permalink
🏗️ Don't automatically focus terminal's panel
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Mar 21, 2021
1 parent 784df21 commit d21c24c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/interface/components/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ let terminalPanel

export default function TerminalComp() {
function TerminalMounted() {
terminalPanel = new Panel(this).element
terminalPanel = new Panel(this, {
autoFocus: false,
}).element
}

return element({
Expand Down
15 changes: 12 additions & 3 deletions src/interface/constructors/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RunningConfig from 'RunningConfig'
import ContextMenu from './contextmenu'
import tabsUnsavedWarningDialog from '../defaults/dialogs/tabs_unsaved_warning'
import PuffinElement from 'Types/puffin.element'
import { PanelOptions } from 'Types/panel'

function guessTabPosition(tab, tabsbar) {
const res = Object.keys(tabsbar.children).find((tabChildren, index) => {
Expand All @@ -14,9 +15,15 @@ function guessTabPosition(tab, tabsbar) {
return Number(res)
}

const defaultOptions = {
autoFocus: true,
}

class Panel {
element: PuffinElement
constructor(containerElement = document.getElementById('panels_stack')) {
options: PanelOptions
constructor(containerElement = document.getElementById('panels_stack'), options?: PanelOptions) {
this.options = options || defaultOptions
const self = this
const PanelComp = element({
components: {
Expand Down Expand Up @@ -122,10 +129,12 @@ class Panel {
}

this.element = render(PanelComp, containerElement)
RunningConfig.data.focusedPanel = this.element
const panelElement = this.element as any
panelElement.focusPanel = this.focusPanel.bind(this)
this.focusPanel()
}
focusPanel() {
RunningConfig.data.focusedPanel = this.element
if (this.options.autoFocus) RunningConfig.data.focusedPanel = this.element
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/interface/constructors/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class Tab {
const focusedMeListener = this.tabState.on('focusedMe', ({ justCreated = false } = {}) => {
if (this.tabState.data.active && justCreated === false) return
RunningConfig.data.focusedTab = this.tabElement
RunningConfig.data.focusedPanel = this.tabElement.parentElement.parentElement
const tabPanel = <any>this.tabElement.parentElement.parentElement
tabPanel.focusPanel()
if (!this.tabState.data.active) unfocusActiveTab(this.tabElement.parentElement)
RunningConfig.emit('aTabHasBeenFocused', {
tabElement: this.tabElement,
Expand Down
3 changes: 3 additions & 0 deletions src/interface/types/panel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PanelOptions {
autoFocus: boolean
}

0 comments on commit d21c24c

Please sign in to comment.