forked from Mirrors/apostrophe
Add search and replace to the undo stack as a single action
This is specially important for search and replace *all*.github/fork/yochananmarqos/patch-1
parent
aa3f5c3430
commit
0b6e84bf8c
|
@ -20,6 +20,7 @@
|
|||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from contextlib import contextmanager
|
||||
|
||||
import gi
|
||||
import pypandoc
|
||||
|
@ -52,6 +53,13 @@ def get_builder(builder_file_name):
|
|||
return builder
|
||||
|
||||
|
||||
@contextmanager
|
||||
def user_action(text_buffer):
|
||||
text_buffer.begin_user_action()
|
||||
yield text_buffer
|
||||
text_buffer.end_user_action()
|
||||
|
||||
|
||||
def path_to_file(path):
|
||||
"""Return a file path (file:///) for the given path"""
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ import re
|
|||
|
||||
import gi
|
||||
|
||||
from uberwriter.helpers import user_action
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gdk
|
||||
|
||||
|
@ -162,18 +164,20 @@ class SearchAndReplace:
|
|||
self.replace(self.active)
|
||||
|
||||
def replace_all(self, _widget=None, _data=None):
|
||||
for match in reversed(self.matches):
|
||||
self.do_replace(match)
|
||||
with user_action(self.textbuffer):
|
||||
for match in reversed(self.matches):
|
||||
self.__do_replace(match)
|
||||
self.search(scroll=False)
|
||||
|
||||
def replace(self, searchindex, _inloop=False):
|
||||
self.do_replace(self.matches[searchindex])
|
||||
with user_action(self.textbuffer):
|
||||
self.__do_replace(self.matches[searchindex])
|
||||
active = self.active
|
||||
self.search(scroll=False)
|
||||
self.active = active
|
||||
self.scrollto(self.active)
|
||||
|
||||
def do_replace(self, match):
|
||||
def __do_replace(self, match):
|
||||
start_iter = self.textbuffer.get_iter_at_offset(match[0])
|
||||
end_iter = self.textbuffer.get_iter_at_offset(match[1])
|
||||
self.textbuffer.delete(start_iter, end_iter)
|
||||
|
|
Loading…
Reference in New Issue