Saving the caret position in editor

This commit is contained in:
Sigmanor 2016-01-23 21:24:56 +02:00
parent f619cc6777
commit f4bc5b860b

View file

@ -27,6 +27,7 @@ public partial class MainWindow : Form
public static bool textSave = false; public static bool textSave = false;
public static string[] args = Environment.GetCommandLineArgs(); public static string[] args = Environment.GetCommandLineArgs();
Properties.Settings ps = Properties.Settings.Default; Properties.Settings ps = Properties.Settings.Default;
int caretPos = 0;
public MainWindow() public MainWindow()
{ {
@ -650,6 +651,7 @@ private void searchTextBox_KeyDown(object sender, KeyEventArgs e)
customRTB.Height = customRTB.Height += 27; customRTB.Height = customRTB.Height += 27;
customRTB.Focus(); customRTB.Focus();
customRTB.DeselectAll(); customRTB.DeselectAll();
customRTB.SelectionStart = caretPos;
e.Handled = e.SuppressKeyPress = true; e.Handled = e.SuppressKeyPress = true;
} }
} }
@ -752,7 +754,7 @@ private void findToolStripMenuItem2_Click(object sender, EventArgs e)
{ {
panel1.Visible = true; panel1.Visible = true;
searchTextBox.Focus(); searchTextBox.Focus();
SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1)); //SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1));
customRTB.Height = customRTB.Height - 27; customRTB.Height = customRTB.Height - 27;
return; return;
} }
@ -763,11 +765,11 @@ private void findToolStripMenuItem2_Click(object sender, EventArgs e)
panel1.Visible = false; panel1.Visible = false;
customRTB.Height = customRTB.Height += 27; customRTB.Height = customRTB.Height += 27;
customRTB.Focus(); customRTB.Focus();
SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(1)); //SendMessage(customRTB.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(1));
customRTB.DeselectAll(); customRTB.DeselectAll();
customRTB.SelectionStart = caretPos;
return;
} }
string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
customRTB.Select(Convert.ToInt32(cc2), 0);
} }
private void documentationToolStripMenuItem_Click(object sender, EventArgs e) private void documentationToolStripMenuItem_Click(object sender, EventArgs e)
@ -946,6 +948,7 @@ void AutoLock(bool minimize)
string saveText = customRTB.Text; string saveText = customRTB.Text;
Form2 f2 = new Form2(); Form2 f2 = new Form2();
key = ""; key = "";
caretPos = customRTB.SelectionStart;
this.Hide(); this.Hide();
if (minimize == true) if (minimize == true)
{ {
@ -978,7 +981,7 @@ void AutoLock(bool minimize)
textSave = false; textSave = false;
string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture); string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
customRTB.Select(Convert.ToInt32(cc2), 0); customRTB.SelectionStart = caretPos;
textSave = true; textSave = true;
this.Show(); this.Show();
} }
@ -1039,5 +1042,15 @@ private void lockToolStripMenuItem_Click(object sender, EventArgs e)
deleteFileToolStripMenuItem.Enabled = true; deleteFileToolStripMenuItem.Enabled = true;
} }
} }
private void customRTB_Click(object sender, EventArgs e)
{
caretPos = customRTB.SelectionStart;
}
private void customRTB_KeyDown(object sender, KeyEventArgs e)
{
caretPos = customRTB.SelectionStart;
}
} }
} }