B2016-281 - handle when text is selected (highlighted) and the first keystroke is a dash or backslash. Also handle when dash or backslash is entered between two links such as two ROs that are butt up against each other.

This commit is contained in:
John Jenko 2017-01-18 17:00:30 +00:00
parent 5e01c873ae
commit 431503a104

View File

@ -1209,7 +1209,7 @@ namespace Volian.Controls.Library
} }
private string GetAddSymbolText(string symtxt) private string GetAddSymbolText(string symtxt)
{ {
return (@"{\f0\fs" + this.Font.SizeInPoints * 2 + @" " + symtxt + @"}"); return (@"{\f1\fs" + this.Font.SizeInPoints * 2 + @" " + symtxt + @"}"); // B2016-281 fixed font selection when inserting a symbol character
} }
public void AddRtfLink(string linkUrl, string linkValue) public void AddRtfLink(string linkUrl, string linkValue)
{ {
@ -2525,29 +2525,37 @@ namespace Volian.Controls.Library
// add the character with its font depending on the char.... // add the character with its font depending on the char....
if (!IsControlChar) if (!IsControlChar)
{ {
string strpressed = null;
if (e.KeyChar == '-')
strpressed = GetAddSymbolText(@"\u8209?");
else if (e.KeyChar == '\\')
strpressed = GetAddSymbolText(@"\u9586?");
else
strpressed = e.KeyChar.ToString();
if (e.KeyChar >= ' ') if (e.KeyChar >= ' ')
{ {
// B2016-281 if entered keystroke is a character that converted to a symbol (i.e. dash or backslash)
// or if it's a RFT special character (i.e. open and close curly brackets)
// then flag it and replace selected text with a null string (removing selected text)
// and then insert the symbol or RTF escape codes for those characters
bool isSymbolOrRTF = e.KeyChar == '-' || e.KeyChar == '\\' || e.KeyChar == '{' || e.KeyChar == '}';
LinkLocation ll = FindBetweenLinks(); LinkLocation ll = FindBetweenLinks();
if (ll != null && SelectionLength == 0) // SelectionLength = 0 means insert if (ll != null && SelectionLength == 0) // SelectionLength = 0 means insert
{ {
if (e.KeyChar == '}') // replacing between links, this is a special case
string strpressed = null;
if (e.KeyChar == '-')
strpressed = GetAddSymbolText(@"\u8209?");
else if (e.KeyChar == '\\')
strpressed = GetAddSymbolText(@"\u9586?");
else if (e.KeyChar == '}')
strpressed = @"\}"; strpressed = @"\}";
else if (e.KeyChar == '{') else if (e.KeyChar == '{')
strpressed = @"\{"; strpressed = @"\{";
InsertCharBetweenLinks(ll, strpressed); // e.KeyChar); else
strpressed = e.KeyChar.ToString();
InsertCharBetweenLinks(ll, strpressed);
e.Handled = true; e.Handled = true;
} }
else if (SelectionLength != 0) else if (SelectionLength != 0)
{ {
HandleDeleteKeyWithSelectedText(new KeyEventArgs(Keys.None), strpressed); // B2016-281 if replacing with a dash, backslash, or curly brackets, first replace with nother (to delete selection)
e.Handled = true; // and set the e.Handled to false so that AddSybol or AddRTF is used to insert that character.
HandleDeleteKeyWithSelectedText(new KeyEventArgs(Keys.None), isSymbolOrRTF ? "" : e.KeyChar.ToString());
e.Handled = !isSymbolOrRTF;
} }
} }
if (!e.Handled) if (!e.Handled)
@ -2560,7 +2568,6 @@ namespace Volian.Controls.Library
AddRtf(@"\}"); AddRtf(@"\}");
else if (e.KeyChar == '\\') else if (e.KeyChar == '\\')
AddSymbol(@"\u9586?"); // unicode hex 2572 AddSymbol(@"\u9586?"); // unicode hex 2572
//AddRtf(@"\\");
else else
return; return;
e.Handled = true; // flag that it's been handled, otherwise, will get 2 chars. e.Handled = true; // flag that it's been handled, otherwise, will get 2 chars.