Skip to content

Commit 8bf2357

Browse files
committed
#30 restrict cut/copy in password fields
1 parent c6f7748 commit 8bf2357

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

view_input.v

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ fn (cfg &InputCfg) on_char_shape(shape &Shape, mut event Event, mut w Window) {
128128
}
129129
} else if event.modifiers & u32(Modifier.ctrl) > 0 {
130130
match c {
131-
ctrl_v { text = cfg.paste(from_clipboard(), mut w) or { '' } }
132-
ctrl_x { text = cfg.cut(mut w) or { '' } }
131+
ctrl_v { text = cfg.paste(from_clipboard(), mut w) or { return } }
132+
ctrl_x { text = cfg.cut(mut w) or { return } }
133133
ctrl_z { text = cfg.undo(mut w) }
134134
else {}
135135
}
136136
} else if event.modifiers & u32(Modifier.super) > 0 {
137137
match c {
138-
cmd_v { text = cfg.paste(from_clipboard(), mut w) or { '' } }
139-
cmd_x { text = cfg.cut(mut w) or { '' } }
138+
cmd_v { text = cfg.paste(from_clipboard(), mut w) or { return } }
139+
cmd_x { text = cfg.cut(mut w) or { return } }
140140
cmd_z { text = cfg.undo(mut w) }
141141
else {}
142142
}
@@ -275,11 +275,17 @@ fn (cfg &InputCfg) insert(s string, mut w Window) !string {
275275
}
276276

277277
pub fn (cfg &InputCfg) cut(mut w Window) ?string {
278+
if cfg.is_password {
279+
return none
280+
}
278281
cfg.copy(w)
279282
return cfg.delete(mut w, false)
280283
}
281284

282285
pub fn (cfg &InputCfg) copy(w &Window) ?string {
286+
if cfg.is_password {
287+
return none
288+
}
283289
input_state := w.view_state.input_state[cfg.id_focus]
284290
if input_state.select_beg != input_state.select_end {
285291
beg, end := u32_sort(input_state.select_beg, input_state.select_end)
@@ -288,9 +294,7 @@ pub fn (cfg &InputCfg) copy(w &Window) ?string {
288294
return none
289295
}
290296
cpy := cfg.text[beg..end] or { '' }
291-
if !cfg.is_password {
292-
to_clipboard(cpy)
293-
}
297+
to_clipboard(cpy)
294298
}
295299
return none
296300
}

0 commit comments

Comments
 (0)