Skip to content

Commit

Permalink
feat(selection): add noTypeField
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 11, 2018
1 parent bbdbcbf commit f395f8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export interface AppConfigMutable {
/** activate app, won't affect triple-ctrl setting */
active: boolean

/** disable selection on type fields, like input and textarea */
noTypeField: boolean

/** use animation for transition */
animation: boolean

Expand Down Expand Up @@ -359,6 +362,8 @@ export function appConfigFactory (): AppConfig {

active: true,

noTypeField: false,

animation: true,

langCode,
Expand Down
35 changes: 30 additions & 5 deletions src/selection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,36 @@ const tripleCtrlPressed$ = validCtrlPressed$$.pipe(
)

const validMouseup$$ = fromEvent<MouseEvent>(window, 'mouseup', { capture: true }).pipe(
filter(({ target }) => (
config.active &&
window.name !== 'saladict-frame' &&
(!target || typeof target['className'] !== 'string' || !target['className'].startsWith('saladict-'))
)),
filter(({ target }) => {
if (!config.active || window.name === 'saladict-frame') {
return false
}

if (!target) { return true }

if (typeof target['className'] === 'string' && target['className'].startsWith('saladict-')) {
return false
}

if (config.noTypeField) {
if (target['tagName'] === 'INPUT' || target['tagName'] === 'TEXTAREA') {
return false
}

if (!target['classList'] || !target['parentElement']) {
return true
}

// Popular code editors CodeMirror and ACE
for (let el = target as Element | null; el; el = el.parentElement) {
if (el.classList.contains('CodeMirror') || el.classList.contains('ace_editor')) {
return false
}
}
}

return true
}),
// if user click on a selected text,
// getSelection would reture the text before the highlight disappears
// delay to wait for selection get cleared
Expand Down

0 comments on commit f395f8c

Please sign in to comment.