Skip to content

Commit 7857bba

Browse files
committed
(fix) set cursor position on Firefox & Safari
1 parent 23134f9 commit 7857bba

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/lib/Room/RoomFooter/RoomFooter.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ import vClickOutside from '../../../utils/on-click-outside'
201201
import filteredItems from '../../../utils/filter-items'
202202
import Recorder from '../../../utils/recorder'
203203
204+
import { detectChrome } from '../../../utils/browser-detection'
204205
import { detectMobile } from '../../../utils/mobile-detection'
205206
206207
export default {
@@ -394,9 +395,10 @@ export default {
394395
395396
if (this.cursorRangePosition) {
396397
setTimeout(() => {
398+
const offset = detectChrome() ? 0 : 1
397399
this.getTextareaRef().setSelectionRange(
398-
this.cursorRangePosition,
399-
this.cursorRangePosition
400+
this.cursorRangePosition + offset,
401+
this.cursorRangePosition + offset
400402
)
401403
this.cursorRangePosition = null
402404
})
@@ -445,13 +447,13 @@ export default {
445447
updateActiveUpOrDown(event, direction) {
446448
if (this.filteredEmojis.length) {
447449
this.activeUpOrDownEmojis = direction
448-
event.preventDefault()
450+
event.preventDefault()
449451
} else if (this.filteredUsersTag.length) {
450452
this.activeUpOrDownUsersTag = direction
451-
event.preventDefault()
453+
event.preventDefault()
452454
} else if (this.filteredTemplatesText.length) {
453455
this.activeUpOrDownTemplatesText = direction
454-
event.preventDefault()
456+
event.preventDefault()
455457
}
456458
},
457459
selectItem() {

src/utils/browser-detection.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var isChromium = window.chrome
2+
var winNav = window.navigator
3+
var vendorName = winNav.vendor
4+
var isOpera = typeof window.opr !== 'undefined'
5+
var isIEedge = winNav.userAgent.indexOf('Edg') > -1
6+
var isIOSChrome = winNav.userAgent.match('CriOS')
7+
8+
export function detectChrome() {
9+
if (isIOSChrome) {
10+
return true
11+
} else if (
12+
isChromium !== null &&
13+
typeof isChromium !== 'undefined' &&
14+
vendorName === 'Google Inc.' &&
15+
isOpera === false &&
16+
isIEedge === false
17+
) {
18+
return true
19+
} else {
20+
return false
21+
}
22+
}

0 commit comments

Comments
 (0)