refactor: asterik length same as real text length
This commit is contained in:
@@ -115,7 +115,7 @@ const emit = defineEmits<{
|
|||||||
(e: "click", ev: any): void
|
(e: "click", ev: any): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const ASTERISK = "******"
|
const asterikedText = computed(() => "*".repeat(props.modelValue.length))
|
||||||
|
|
||||||
const cachedValue = ref(props.modelValue)
|
const cachedValue = ref(props.modelValue)
|
||||||
|
|
||||||
@@ -277,19 +277,18 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const prevModelValue = ref(props.modelValue)
|
const prevModelValue = ref(props.modelValue)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.secret,
|
() => props.secret,
|
||||||
(newValue, oldValue) => {
|
(newValue) => {
|
||||||
if (newValue !== oldValue) {
|
let visibleValue = asterikedText.value
|
||||||
let visibleValue = ASTERISK
|
if (!newValue) {
|
||||||
if (!newValue) {
|
visibleValue = prevModelValue.value
|
||||||
visibleValue = prevModelValue.value
|
} else {
|
||||||
} else {
|
prevModelValue.value = props.modelValue
|
||||||
prevModelValue.value = props.modelValue
|
|
||||||
}
|
|
||||||
emit("update:modelValue", visibleValue)
|
|
||||||
updateEditorViewTheme(newValue)
|
|
||||||
}
|
}
|
||||||
|
emit("update:modelValue", visibleValue)
|
||||||
|
updateEditorViewTheme(newValue)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -403,7 +402,7 @@ const initView = (el: any) => {
|
|||||||
el.addEventListener("keyup", debounceFn)
|
el.addEventListener("keyup", debounceFn)
|
||||||
|
|
||||||
if (props.secret) {
|
if (props.secret) {
|
||||||
emit("update:modelValue", ASTERISK)
|
emit("update:modelValue", asterikedText.value)
|
||||||
}
|
}
|
||||||
const extensions: Extension = getExtensions(props.readonly || props.secret)
|
const extensions: Extension = getExtensions(props.readonly || props.secret)
|
||||||
view.value = new EditorView({
|
view.value = new EditorView({
|
||||||
@@ -470,9 +469,14 @@ const getExtensions = (readonly: boolean): Extension => {
|
|||||||
// We do not update the cache directly in this case (to trigger value watcher to dispatch)
|
// We do not update the cache directly in this case (to trigger value watcher to dispatch)
|
||||||
// So, we desync cachedValue a bit so we can trigger updates
|
// So, we desync cachedValue a bit so we can trigger updates
|
||||||
const value = clone(cachedValue.value).replaceAll("\n", "")
|
const value = clone(cachedValue.value).replaceAll("\n", "")
|
||||||
|
if (props.secret) {
|
||||||
emit("update:modelValue", value)
|
const asterikedValue = "*".repeat(value.length)
|
||||||
emit("change", value)
|
emit("update:modelValue", asterikedValue)
|
||||||
|
emit("change", asterikedValue)
|
||||||
|
} else {
|
||||||
|
emit("update:modelValue", value)
|
||||||
|
emit("change", value)
|
||||||
|
}
|
||||||
|
|
||||||
const pasted = !!update.transactions.find((txn) =>
|
const pasted = !!update.transactions.find((txn) =>
|
||||||
txn.isUserEvent("input.paste")
|
txn.isUserEvent("input.paste")
|
||||||
|
|||||||
Reference in New Issue
Block a user