<commit_before>author = '<NAME><<EMAIL>>'
name = 'Search'
desc = 'Searches words in document'

import re
import weakref

import gtk
import glib

from snaked.util import idle, refresh_gui

active_widgets = weakref.WeakKeyDictionary()
search_selections = []
mark_task_is_in_queue = [False]

class SearchSelection(object):
    def __init__(self, search):
        self.search = search

def init(manager):
    manager.add_shortcut('search', '<ctrl>f', 'Edit', 'Search or mark', search)
    manager.add_shortcut('find-next', '<ctrl>j', 'Edit', 'Find next', find_next)
    manager.add_shortcut('find-prev', '<ctrl>k', 'Edit', 'Find prev', find_prev)
    manager.add_shortcut('mark-selection', '<ctrl>h', 'Edit',
        'Mark selection occurrences', mark_selection)

    manager.add_global_option('SEARCH_IGNORE_CASE', False, 'Ignore case while searching')
    manager.add_global_option('SEARCH_REGEX', False, 'Use regular expression for searhing')

def search(editor):
    if editor in active_widgets:
        widget = active_widgets[editor]
    else:
        widget = create_widget(editor)
        active_widgets[editor] = widget
        editor.widget.pack_start(widget, False)
        editor.push_escape(hide, widget)
        widget.show_all()

    if editor.buffer.get_has_selection():
        start, end = editor.buffer.get_selection_bounds()
        if start.get_line() == end.get_line():
            refresh_gui()

            search = start.get_text(end)
            if widget.regex.get_active():
                search = re.escape(search)

            widget.entry.set_text(search)
            editor.buffer.place_cursor(start)
            on_search_activate(widget.entry, editor, widget)
        else:
            widget.entry.grab_focus()
    else:
        widget.entry.grab_focus()

def backward_search(matcher, text, endpos):
    match = None
    for m in matcher.finditer(text):
        if m.end() > endpos:
            return match
        match = m

    return match

def do_find(editor, dir, start_from=None):
    if editor in active_widgets:
        search = active_widgets[editor].entry.get_text()
        ignore_case = active_widgets[editor].ignore_case.get_active()
        regex = active_widgets[editor].regex.get_active()<commit_msg>search: fix double mark<commit_after>author = '<NAME><<EMAIL>>'
name = 'Search'
desc = 'Searches words in document'

import re
import weakref

import gtk
import glib

from snaked.util import idle, refresh_gui

active_widgets = weakref.WeakKeyDictionary()
search_selections = []
mark_task_is_in_queue = [False]

class SearchSelection(object):
    def __init__(self, search):
        self.search = search

def init(manager):
    manager.add_shortcut('search', '<ctrl>f', 'Edit', 'Search or mark', search)
    manager.add_shortcut('find-next', '<ctrl>j', 'Edit', 'Find next', find_next)
    manager.add_shortcut('find-prev', '<ctrl>k', 'Edit', 'Find prev', find_prev)
    manager.add_shortcut('mark-selection', '<ctrl>h', 'Edit',
        'Mark selection occurrences', mark_selection)

    manager.add_global_option('SEARCH_IGNORE_CASE', False, 'Ignore case while searching')
    manager.add_global_option('SEARCH_REGEX', False, 'Use regular expression for searhing')

def search(editor):
    if editor in active_widgets:
        widget = active_widgets[editor]
    else:
        widget = create_widget(editor)
        active_widgets[editor] = widget
        editor.widget.pack_start(widget, False)
        editor.push_escape(hide, widget)
        widget.show_all()

    if editor.buffer.get_has_selection():
        start, end = editor.buffer.get_selection_bounds()
        if start.get_line() == end.get_line():
            refresh_gui()

            search = start.get_text(end)
            if widget.regex.get_active():
                search = re.escape(search)

            editor.buffer.place_cursor(start)
            widget.entry.set_text(search)
        else:
            widget.entry.grab_focus()
    else:
        widget.entry.grab_focus()

def backward_search(matcher, text, endpos):
    match = None
    for m in matcher.finditer(text):
        if m.end() > endpos:
            return match
        match = m

    return match

def do_find(editor, dir, start_from=None):
    if editor in active_widgets:
        search = active_widgets[editor].entry.get_text()
        ignore_case = active_widgets[editor].ignore_case.get_active()
        regex = active_widgets[editor].regex.get_active()
{'fraction_non_alphanumeric': 0.11558353946480773, 'fraction_numerical': 0.0, 'mean_word_length': 3.2041587901701325, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '226636', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1332, 'n_words': 299}