changeset 77e8bde155b1 in tryton:6.2 details: https://hg.tryton.org/tryton?cmd=changeset&node=77e8bde155b1 description: Delete selection when replacing keypad keys
issue11112 review377911002 (grafted from f337cd27fb442d14d1a12928f27982fa6466739b) diffstat: tryton/common/cellrendererfloat.py | 18 ++++++++++++------ tryton/common/number_entry.py | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diffs (46 lines): diff -r 123adfc4f979 -r 77e8bde155b1 tryton/common/cellrendererfloat.py --- a/tryton/common/cellrendererfloat.py Tue Feb 01 18:15:50 2022 +0100 +++ b/tryton/common/cellrendererfloat.py Tue Jan 11 23:05:35 2022 +0100 @@ -29,18 +29,24 @@ for name in ('KP_Decimal', 'KP_Separator'): if event.keyval == Gdk.keyval_from_name(name): text = self.__decimal_point - position = widget.props.cursor_position - if self._can_insert_text(widget, text, position): + try: + start_pos, end_pos = widget.get_selection_bounds() + except ValueError: + start_pos = widget.props.cursor_position + end_pos = None + if self._can_insert_text(widget, text, start_pos, end_pos): buffer_ = widget.get_buffer() - buffer_.insert_text(position, text, len(text)) + buffer_.delete_text(start_pos, end_pos - start_pos) + buffer_.insert_text(start_pos, text, len(text)) widget.set_position( widget.props.cursor_position + len(text)) return True - def _can_insert_text(self, entry, new_text, position): + def _can_insert_text(self, entry, new_text, start_pos, end_pos=None): value = entry.get_text() - position = entry.get_position() - new_value = value[:position] + new_text + value[position:] + if end_pos is None: + end_pos = start_pos + new_value = value[:start_pos] + new_text + value[end_pos:] if new_value not in {'-', self.__decimal_point, self.__thousands_sep}: try: value = locale.atof(new_value) diff -r 123adfc4f979 -r 77e8bde155b1 tryton/common/number_entry.py --- a/tryton/common/number_entry.py Tue Feb 01 18:15:50 2022 +0100 +++ b/tryton/common/number_entry.py Tue Jan 11 23:05:35 2022 +0100 @@ -73,6 +73,8 @@ for name in ['KP_Decimal', 'KP_Separator']: if event.keyval == Gdk.keyval_from_name(name): text = self.__decimal_point + if self.get_selection_bounds(): + self.delete_text(*self.get_selection_bounds()) self.do_insert_text( text, len(text), self.props.cursor_position) self.set_position(self.props.cursor_position + len(text))