Skip to content

Commit

Permalink
[harbour-seabass] change floating button position when toggling searc…
Browse files Browse the repository at this point in the history
…h panel
  • Loading branch information
milikhin committed Jul 21, 2024
1 parent bb74e3e commit b39800b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions editor/__tests__/app/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('SeabassAppModel', () => {
content: uuid(),
editorConfig: { indent_size: 1, tab_width: 1 },
filePath: uuid(),
isReadOnly: false
isReadOnly: false,
}

it('should open new Editor', () => {
Expand Down Expand Up @@ -58,7 +58,8 @@ describe('SeabassAppModel', () => {
hasUndo: false,
hasRedo: false,
filePath: options.filePath,
isReadOnly: options.isReadOnly
isReadOnly: options.isReadOnly,
searchPanelHeight: 0
})
})
})
Expand Down
4 changes: 4 additions & 0 deletions editor/src/app/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default class SeabassView {
* Shows welcome note, hides tabs interface
*/
showWelcomeScreen (): void {
if (!this._welcomeElem) {
return
}

this._welcomeElem.style.display = 'block'
this._rootElem.style.display = 'none'
}
Expand Down
15 changes: 9 additions & 6 deletions editor/src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class Editor extends EventTarget {
ON_CHANGE_TIMEOUT = 250
SCROLL_INTO_VIEW_TIMEOUT = 250
OSK_SCROLL_DELAY = 100
SEARCH_BTN_QUERY = '.editor .cm-editor .cm-panel.cm-search'

constructor (options: EditorOptions) {
super()
Expand All @@ -72,9 +73,12 @@ export default class Editor extends EventTarget {
placeSearchOnTop: options.placeSearchOnTop
})

// listen to SearchPanel events
const updateListenerExtension = EditorView.updateListener.of(this._onChange.bind(this));

// set initial editor state
this._initialState = EditorState.create({
extensions: this._setup.extensions,
extensions: [...this._setup.extensions, updateListenerExtension],
doc: options.content
})
this._isOskVisible = false
Expand Down Expand Up @@ -225,7 +229,6 @@ export default class Editor extends EventTarget {
} else {
openSearchPanel(this._editor)
}
this._onChange()
}

/**
Expand All @@ -234,15 +237,15 @@ export default class Editor extends EventTarget {
*/
getUiState (): SeabassEditorState {
const isSearchPanelOpened = searchPanelOpen(this._editor.state)

const searchPanelHeight = isSearchPanelOpened
? document.querySelector(this.SEARCH_BTN_QUERY)?.clientHeight ?? 0
: 0
return {
hasChanges: !this._isReadOnly && !this._editor.state.doc.eq(this._initialState.doc),
hasUndo: !this._isReadOnly && undoDepth(this._editor.state) > 0,
hasRedo: !this._isReadOnly && redoDepth(this._editor.state) > 0,
isReadOnly: this._isReadOnly,
searchPanelHeight: isSearchPanelOpened
? document.querySelector('.harbour .editor .cm-editor .cm-panel.cm-search')?.clientHeight ?? 0
: 0
searchPanelHeight: searchPanelHeight * window.devicePixelRatio
}
}

Expand Down
2 changes: 1 addition & 1 deletion harbour-seabass/qml/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

.harbour .editor .cm-editor .cm-panel.cm-search button[name="close"] {
padding: 5px;
padding: 7px;
font-size: 1rem;
}
</style>
Expand Down
5 changes: 3 additions & 2 deletions harbour-seabass/qml/pages/Editor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ WebViewPage {
enabled: hasOpenedFile
onClicked: {
api.postMessage('toggleSearchPanel')
isMenuEnabled = !isMenuEnabled
}
}
MenuItem {
Expand Down Expand Up @@ -333,9 +334,9 @@ WebViewPage {

// Floating action button to enable pulley menus
PlatformComponents.FloatingButton {
anchors.bottom: (toolbar.open ? toolbar.top : parent.bottom) + editorState.searchPanelHeight
anchors.bottom: toolbar.open ? toolbar.top : parent.bottom
anchors.right: parent.right
anchors.bottomMargin: Theme.paddingMedium
anchors.bottomMargin: Theme.paddingMedium + editorState.searchPanelHeight
anchors.rightMargin: Theme.paddingMedium
visible: hasOpenedFile

Expand Down

0 comments on commit b39800b

Please sign in to comment.