Skip to content

Commit

Permalink
$mol_format dynamic mask cursor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 25, 2024
1 parent 3cbf060 commit 8203550
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions format/format.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ namespace $.$$ {
const mask = this.mask( filtered )

if( ( prev?.[0] ?? 0 ) >= from ) return [ from, to ]

const lastAllow = ( value.length - [ ... value ].reverse().findIndex( letter => allow.includes( letter ) ) )%(value.length+1)

const lastAllow = (
value.length - [ ... value ].reverse().findIndex( letter => allow.includes( letter ) )
) % ( value.length + 1 )

if( lastAllow < from ) {
from = to = lastAllow
}
Expand All @@ -29,9 +32,23 @@ namespace $.$$ {
++ from
++ to
}


// Если по-сравнению с this.mask_prev в mask добавились/удалились не подчервивания слева от from
// То надо увеличить/уменьшить from и to, на кол-во добавленных/удаленных символов
const before = mask.slice(0, from).replace(/_/g, '').length
const before_prev = this.mask_prev.slice(0, from).replace(/_/g, '').length
let delta = before - before_prev

from += delta
to += delta


this.mask_prev = mask

return [ from, to ]
}

protected mask_prev = ''

@ $mol_mem
value_changed( next?: string ) {
Expand Down

0 comments on commit 8203550

Please sign in to comment.