From b48684323775c185d33ad308cb3c8a21b0987132 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 25 Jan 2014 14:32:23 +0000 Subject: [PATCH] Working on spell check... git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2426 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/SpellCheck.cs | 78 +++++++++-------------------------------- 1 file changed, 17 insertions(+), 61 deletions(-) diff --git a/src/Forms/SpellCheck.cs b/src/Forms/SpellCheck.cs index e49c09851..b63620756 100644 --- a/src/Forms/SpellCheck.cs +++ b/src/Forms/SpellCheck.cs @@ -175,68 +175,24 @@ namespace Nikse.SubtitleEdit.Forms richTextBoxParagraph.SelectionColor = Color.Black; richTextBoxParagraph.SelectionLength = 0; - int newLine1 = int.MaxValue; - int newLine2 = int.MaxValue; - if (word.Text.Contains(Environment.NewLine)) + for (int i = 0; i < 10; i++) { - newLine1 = word.Text.IndexOf(Environment.NewLine); - if (word.Text.IndexOf(Environment.NewLine, newLine1 + 1) > 0) - newLine2 = word.Text.IndexOf(Environment.NewLine, newLine1 + 1); - } - - int idx = word.Index; - if (idx > 0 && !richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) - idx--; - - if (richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) - { - if (idx > newLine1) - idx--; - if (idx > newLine2) - idx--; - richTextBoxParagraph.SelectionStart = idx; - richTextBoxParagraph.SelectionLength = word.Text.Length; - richTextBoxParagraph.SelectionColor = Color.Red; - } - else if (richTextBoxParagraph.Text.Substring(idx + 1).StartsWith(word.Text)) - { - if (idx > newLine1) - idx--; - if (idx > newLine2) - idx--; - richTextBoxParagraph.SelectionStart = idx + 1; - richTextBoxParagraph.SelectionLength = word.Text.Length; - richTextBoxParagraph.SelectionColor = Color.Red; - } - else if (richTextBoxParagraph.Text.Substring(idx + 2).StartsWith(word.Text)) - { - if (idx > newLine1) - idx--; - if (idx > newLine2) - idx--; - richTextBoxParagraph.SelectionStart = idx + 2; - richTextBoxParagraph.SelectionLength = word.Text.Length; - richTextBoxParagraph.SelectionColor = Color.Red; - } - else if (richTextBoxParagraph.Text.Substring(idx + 3).StartsWith(word.Text)) - { - if (idx > newLine1) - idx--; - if (idx > newLine2) - idx--; - richTextBoxParagraph.SelectionStart = idx + 3; - richTextBoxParagraph.SelectionLength = word.Text.Length; - richTextBoxParagraph.SelectionColor = Color.Red; - } - else if (idx > 2 && richTextBoxParagraph.Text.Substring(idx -2).StartsWith(word.Text)) - { - if (idx > newLine1) - idx--; - if (idx > newLine2) - idx--; - richTextBoxParagraph.SelectionStart = idx -2; - richTextBoxParagraph.SelectionLength = word.Text.Length; - richTextBoxParagraph.SelectionColor = Color.Red; + int idx = word.Index - i; + if (i >= 0 && i < richTextBoxParagraph.Text.Length && richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) + { + richTextBoxParagraph.SelectionStart = idx; + richTextBoxParagraph.SelectionLength = word.Text.Length; + richTextBoxParagraph.SelectionColor = Color.Red; + break; + } + idx = word.Index + i; + if (i >= 0 && i < richTextBoxParagraph.Text.Length && richTextBoxParagraph.Text.Substring(idx).StartsWith(word.Text)) + { + richTextBoxParagraph.SelectionStart = idx; + richTextBoxParagraph.SelectionLength = word.Text.Length; + richTextBoxParagraph.SelectionColor = Color.Red; + break; + } } }