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

[stable28] Fix/5080 keep menubar in workspace #5195

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<template v-else>
<MenuBar v-if="renderMenus"
ref="menubar"
:autohide="autohide"
:is-hidden="hideMenu"
:loaded.sync="menubarLoaded">
<Status :document="document"
:dirty="dirty"
Expand Down Expand Up @@ -213,7 +213,7 @@ export default {
type: String,
default: null,
},
autohide: {
hideMenu: {
type: Boolean,
default: false,
},
Expand Down
28 changes: 4 additions & 24 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
:aria-label="t('text', 'Editor actions')"
:class="{
'text-menubar--ready': isReady,
'text-menubar--show': isVisible,
'text-menubar--autohide': autohide,
'text-menubar--hide': isHidden,
'text-menubar--is-workspace': $isRichWorkspace
}">
<HelpModal v-if="displayHelp" @close="hideHelp" />
Expand Down Expand Up @@ -84,7 +83,6 @@
<script>
import { NcActionSeparator, NcActionButton } from '@nextcloud/vue'
import { loadState } from '@nextcloud/initial-state'
import debounce from 'debounce'
import { useResizeObserver } from '@vueuse/core'

import ActionFormattingHelp from './ActionFormattingHelp.vue'
Expand Down Expand Up @@ -136,7 +134,7 @@ export default {
return val
},
props: {
autohide: {
isHidden: {
type: Boolean,
default: false,
},
Expand All @@ -148,7 +146,6 @@ export default {
displayHelp: false,
displayTranslate: false,
isReady: false,
isVisible: this.$editor.isFocused,
canTranslate: loadState('text', 'translation_languages', []).length > 0,
resize: null,
iconsLimit: 4,
Expand Down Expand Up @@ -178,26 +175,13 @@ export default {
mounted() {
this.resize = useResizeObserver(this.$refs.menubar, this.onResize)

this.$onFocusChange = () => {
this.isVisible = this.$editor.isFocused
}
this.$onBlurChange = debounce(() => {
this.isVisible = this.$editor.isFocused
}, 3000) // 3s

this.$editor.on('focus', this.$onFocusChange)
this.$editor.on('blur', this.$onBlurChange)

this.$nextTick(() => {
this.isReady = true
this.$emit('update:loaded', true)
})
},
beforeDestroy() {
this.resize?.stop()

this.$editor.off('focus', this.$onFocusChange)
this.$editor.off('blur', this.$onBlurChange)
},
methods: {
onResize(entries) {
Expand Down Expand Up @@ -274,19 +258,15 @@ export default {
justify-content: flex-end;
align-items: center;

&.text-menubar--ready:not(.text-menubar--autohide) {
&.text-menubar--ready:not(.text-menubar--hide) {
visibility: visible;
animation-name: fadeInDown;
animation-duration: 0.3s;
}

&.text-menubar--autohide {
&.text-menubar--hide {
opacity: 0;
transition: visibility 0.2s 0.4s, opacity 0.2s 0.4s;
&.text-menubar--show {
visibility: visible;
opacity: 1;
}
}
.text-menubar__entries {
display: flex;
Expand Down
26 changes: 5 additions & 21 deletions src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
:share-token="shareToken"
:mime="file.mimetype"
:autofocus="autofocus"
:autohide="autohide"
:hide-menu="hideMenu"
active
rich-workspace
@ready="ready=true"
@focus="onFocus"
@blur="onBlur"
@error="reset" />
</div>
</template>
Expand Down Expand Up @@ -88,7 +87,7 @@ export default {
loaded: false,
ready: false,
autofocus: false,
autohide: true,
hideMenu: true,
darkTheme: OCA.Accessibility && OCA.Accessibility.theme === 'dark',
enabled: OCA.Text.RichWorkspaceEnabled,
}
Expand Down Expand Up @@ -135,11 +134,9 @@ export default {
this.unlistenKeydownEvents()
},
methods: {
onBlur() {
this.listenKeydownEvents()
},
onFocus() {
this.focus = true
this.hideMenu = false
this.unlistenKeydownEvents()
},
reset() {
Expand Down Expand Up @@ -198,25 +195,12 @@ export default {
window.addEventListener('keydown', this.onKeydown)
},
unlistenKeydownEvents() {
clearInterval(this.$_timeoutAutohide)

window.removeEventListener('keydown', this.onKeydown)
},
onTimeoutAutohide() {
this.autohide = true
},
onKeydown(e) {
if (e.key !== 'Tab') {
return
if (e.key === 'Tab') {
this.hideMenu = false
}

// remove previous timeout
clearInterval(this.$_timeoutAutohide)

this.autohide = false

// schedule to normal behaviour
this.$_timeoutAutohide = setTimeout(this.onTimeoutAutohide, 7000) // 7s
},
onFileCreated(node) {
if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) {
Expand Down