Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.49k stars 170 forks source link

Highlight Occurrences: search for visible matches is slow #5437

Closed Alexey-T closed 6 months ago

Alexey-T commented 6 months ago

search for all mathes is fast and ok

def find_all_occurrences(ed_self, text, case_sensitive, whole_words):
    """
    Finding matches to highlight
    """

    opts = ('c' if case_sensitive else '') + ('w' if whole_words else '')
    log("Calling ed_self.action: EDACTION_FIND_ALL")
    res = ed_self.action(app.EDACTION_FIND_ALL, text, opts, opt.MAX_LINE_LEN)
    res = [r[:2] for r in res]
    return res

it uses EDACTION_FIND_ALL. ie Cud search engine.

  1. search for 'visible' matches is not using Cud engine! it uses Py regex
    items = []
    for i,(x_offset, line) in enumerate(offset_lines):
        if line: # prevent crash if line is None
            for m in re.finditer(re_pattern, line, flags=_re_flags):
                items.append( (x_offset+m.start(), y0+i) )

it is not nice. better rework this part using Cud engine.

Alexey-T commented 6 months ago

reworked!