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

fix: 修复输入框里面很长的内容,选择文本后,功能才到溢出输入框范围 #239

Open
wants to merge 1 commit into
base: pro
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions resources/assets/js/pages/manage/components/ChatInput/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,14 @@ export default {
this.quill = new Quill(this.$refs.editor, this._options)
this.quill.enable(!this.disabled)

// 监听滚动事件
const container = document.querySelector('.ql-container')
const editor = document.querySelector('.ql-editor')
const tooltip = document.querySelector('.ql-tooltip')
$(editor).on('scroll', (e) => {
this.onShowTooltip(container, tooltip, editor)
})

// Set editor content
if (this.value) {
this.setContent(this.value)
Expand All @@ -802,6 +810,8 @@ export default {
this.quill.on('selection-change', range => {
if (range) {
this.selectRange = range
this.quill.setSelection(range.index, range.length)
this.onShowTooltip(container, tooltip, editor)
} else if (this.selectRange && document.activeElement && /(ql-editor|ql-clipboard)/.test(document.activeElement.className)) {
// 修复iOS光标会超出的问题
this.selectTimer && clearTimeout(this.selectTimer)
Expand All @@ -810,6 +820,7 @@ export default {
}, 100)
return
}
//
this.isFocus = !!range;
})

Expand Down Expand Up @@ -1851,6 +1862,25 @@ export default {
visualViewportResize() {
this.viewportHeight = window.visualViewport?.height || 0;
},

onShowTooltip(container, tooltip, editor) {
const tooltipRect = tooltip.getBoundingClientRect();
const editorRect = editor.getBoundingClientRect();

// 如果 tooltip 没有高度,直接返回
if (tooltipRect.height <= 0) {
return;
}

// 检查 tooltip 是否超出编辑器的可视区域
const isOutOfBounds = tooltipRect.top + tooltipRect.height < editorRect.top ||
tooltipRect.bottom > editorRect.bottom;

// 根据是否超出边界设置容器的 overflowY
$(container).css({
overflowY: isOutOfBounds ? 'hidden' : 'visible'
});
}
}
}
</script>