Option Explicit Dim FIND_FLAG FIND_FLAG = eeFindPrevious Or eeFindReplaceCase Or eeFindReplaceRegExp Dim originalBottomX, originalBottomY Dim scrX, scrY Dim wordTopX, wordTopY Dim wordBottomX, wordBottomY Dim phraseTopX, phraseTopY Dim phraseBottomX, phraseBottomY Dim word Dim phrase Dim escapedWord Dim brokenWord Dim escapedPhrase Dim prefixes Dim prefix Dim isFinished prefixes = Array("(\w+\W+|\W+\w+)", "(\W+|\w+)", "") Window.Redraw = false StorePosition word = GetWord escapedWord = AddEscape(word) For Each prefix In prefixes phrase = GetPhrase(prefix & escapedWord) If phrase <> "" Then escapedPhrase = AddEscape(phrase) isFinished = Complete(escapedPhrase & "\w+") If isFinished = false Then isFinished = Complete(escapedPhrase & "([^\w\s]+|\s+)") End If If isFinished = true Then Exit For Next If isFinished = false Then brokenWord = BreakPhrase(escapedWord) For Each prefix In prefixes phrase = GetPhrase(prefix & brokenWord) If phrase <> "" Then phrase = Left(phrase, Len(phrase) - Len(word)) escapedPhrase = AddEscape(phrase) & brokenWord isFinished = Complete(escapedPhrase & "\w*") If isFinished = false Then isFinished = Complete(escapedPhrase & "([^\w\s]+|\s+)") End If If isFinished = true Then Exit For Next End If If isFinished = false Then RestorePosition window.scrollTo scrX, scrY document.HighlightFind = false Window.Redraw = true Sub StorePosition originalBottomX = document.selection.GetBottomPointX(eePosLogical) originalBottomY = document.selection.GetBottomPointY(eePosLogical) scrX = window.scrollX scrY = window.scrollY End Sub Sub RestorePosition document.selection.SetActivePoint eePosLogical, originalBottomX, originalBottomY, false End Sub Function GetWord() 'document.selection.WordLeft, false 'document.selection.WordRight, true document.selection.WordLeft wordTopX = document.selection.GetBottomPointX(eePosLogical) wordTopY = document.selection.GetBottomPointY(eePosLogical) document.selection.WordRight wordBottomX = document.selection.GetBottomPointX(eePosLogical) wordBottomY = document.selection.GetBottomPointY(eePosLogical) document.selection.SetActivePoint eePosLogical, wordTopX, wordTopY, false document.selection.SetActivePoint eePosLogical, wordBottomX, wordBottomY, true GetWord = document.selection.Text End Function Function GetPhrase(str) Dim found RestorePosition document.selection.WordRight found = document.selection.Find(str, FIND_FLAG) document.HighlightFind = false If found <> 0 And IsWordIncluded() = true Then GetPhrase = document.selection.Text phraseTopX = document.selection.GetTopPointX(eePosLogical) phraseTopY = document.selection.GetTopPointY(eePosLogical) phraseBottomX = document.selection.GetBottomPointX(eePosLogical) phraseBottomY = document.selection.GetBottomPointY(eePosLogical) Else GetPhrase = "" End If End Function Function GetCompPhrase(str) Dim found RestorePosition document.selection.WordLeft found = document.selection.Find(str, FIND_FLAG Or eeFindAround) document.HighlightFind = false If found <> 0 And IsWordIncluded() = false Then GetCompPhrase = document.selection.Text Else GetCompPhrase = "" End If End Function Function Complete(str) Dim compPhrase compPhrase = GetCompPhrase(str) If compPhrase <> "" Then document.selection.SetActivePoint eePosLogical, phraseTopX, phraseTopY, false document.selection.SetActivePoint eePosLogical, phraseBottomX, phraseBottomY, true If document.selection.Text <> compPhrase Then document.selection.Text = compPhrase Complete = true Exit Function End If End If Complete = false End Function Function IsWordIncluded() Dim topX, topY Dim bottomX, bottomY topX = document.selection.GetTopPointX(eePosLogical) topY = document.selection.GetTopPointY(eePosLogical) bottomX = document.selection.GetBottomPointX(eePosLogical) bottomY = document.selection.GetBottomPointY(eePosLogical) If topX <= wordTopX And wordTopX <= bottomX _ And topY <= wordTopY And wordTopY <= bottomY Then IsWordIncluded = true Else IsWordIncluded = false End If End Function Function AddEscape(str) Dim i, c For i = 1 To Len(str) c = Mid(str, i, 1) If Instr(".|*?+(){}[]^$\-", c) <> 0 Then c = "\" & c AddEscape = AddEscape & c Next End Function Function BreakPhrase(str) Dim i, c Dim isEscape If Len(str) >= 2 Then isEscape = false For i = 1 To Len(str) -1 c = Mid(str, i, 1) If c = "\" And isEscape = false Then isEscape = true Else isEscape = false End If If c = " " Or c = Chr(9) Then c = c & "\s*?" ElseIf c = "\" Then If isEscape = false Then c = "\" & c & "\w*?" Else c = c & "\w*?" End If BreakPhrase = BreakPhrase & c Next BreakPhrase = BreakPhrase & Right(str, 1) Else BreakPhrase = str End If End Function