Skip to content

Commit

Permalink
fix(selection): track same selection
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 11, 2018
1 parent a79ddf8 commit bbdbcbf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/selection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ tripleCtrlPressed$.subscribe(() => {
message.self.send({ type: MsgType.TripleCtrl })
})

let lastText: string
let lastContext: string
validMouseup$$.subscribe(({ clientX, clientY }) => {
const text = selection.getSelectionText()
if (
Expand All @@ -93,14 +95,24 @@ validMouseup$$.subscribe(({ clientX, clientY }) => {
(config.language.chinese && isContainChinese(text))
)
) {
const context = selection.getSelectionSentence()
if (text === lastText && context === lastContext) {
// Same selection. This could be caused by other widget on the page
// that uses preventDefault which stops selection being cleared when clicked.
// Ignore it so that the panel won't follow.
return
}
lastText = text
lastContext = context

sendMessage(
clientX,
clientY,
clickPeriodCount >= 2,
isCtrlPressed,
{
text: selection.getSelectionText(),
context: selection.getSelectionSentence(),
context,
title: window.pageTitle || document.title,
url: window.pageURL || document.URL,
favicon: window.faviconURL || '',
Expand Down

0 comments on commit bbdbcbf

Please sign in to comment.