Browse Source

Fixed SD2-1191: Using Shift + Backspace with completion window removes extra text

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2074 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
2132d1df6d
  1. 10
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs
  2. 60
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
  3. 5
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/ICompletionDataProvider.cs

10
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultDocument.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.TextEditor.Document @@ -42,7 +42,7 @@ namespace ICSharpCode.TextEditor.Document
/// The indentation from the line above will be
/// taken to indent the curent line
/// </summary>
Auto,
Auto,
/// <summary>
/// Inteligent, context sensitive indentation will occur
@ -91,7 +91,7 @@ namespace ICSharpCode.TextEditor.Document @@ -91,7 +91,7 @@ namespace ICSharpCode.TextEditor.Document
/// The default <see cref="IDocument"/> implementation.
/// </summary>
internal class DefaultDocument : IDocument
{
{
bool readOnly = false;
ILineManager lineTrackingStrategy = null;
@ -334,7 +334,7 @@ namespace ICSharpCode.TextEditor.Document @@ -334,7 +334,7 @@ namespace ICSharpCode.TextEditor.Document
// {
// return lineTrackingStrategy.GetVisibleColumn(logicalLine, logicalColumn);
// }
//
//
public int GetNextVisibleLineAbove(int lineNumber, int lineCount)
{
return lineTrackingStrategy.GetNextVisibleLineAbove(lineNumber, lineCount);
@ -365,7 +365,7 @@ namespace ICSharpCode.TextEditor.Document @@ -365,7 +365,7 @@ namespace ICSharpCode.TextEditor.Document
{
for (int i = 0; i < list.Count; ++i) {
ISegment fm = list[i];
if (e.Offset <= fm.Offset && fm.Offset <= e.Offset + e.Length ||
e.Offset <= fm.Offset + fm.Length && fm.Offset + fm.Length <= e.Offset + e.Length) {
list.RemoveAt(i);
@ -415,7 +415,7 @@ namespace ICSharpCode.TextEditor.Document @@ -415,7 +415,7 @@ namespace ICSharpCode.TextEditor.Document
List<TextAreaUpdate> updateQueue = new List<TextAreaUpdate>();
public List<TextAreaUpdate> UpdateQueue {
get {
get {
return updateQueue;
}
}

60
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.TextEditor.Gui.CompletionWindow
{
@ -17,6 +18,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -17,6 +18,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
CodeCompletionListView codeCompletionListView;
VScrollBar vScrollBar = new VScrollBar();
ICompletionDataProvider dataProvider;
IDocument document;
int startOffset;
int endOffset;
@ -38,6 +40,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -38,6 +40,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
{
this.dataProvider = completionDataProvider;
this.completionData = completionData;
this.document = control.Document;
workingScreen = Screen.GetWorkingArea(Location);
startOffset = control.ActiveTextAreaControl.Caret.Offset + 1;
@ -87,6 +90,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -87,6 +90,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
vScrollBar.ValueChanged += VScrollBarValueChanged;
document.DocumentAboutToBeChanged += DocumentAboutToBeChanged;
}
bool inScrollUpdate;
@ -164,12 +168,13 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -164,12 +168,13 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
{
switch (dataProvider.ProcessKey(ch)) {
case CompletionDataProviderKeyResult.BeforeStartKey:
// increment start + end and process as normal char
// increment start+end, then process as normal char
++startOffset;
goto case CompletionDataProviderKeyResult.NormalKey;
case CompletionDataProviderKeyResult.NormalKey:
++endOffset;
return base.ProcessKeyEvent(ch);
case CompletionDataProviderKeyResult.NormalKey:
// just process normally
return base.ProcessKeyEvent(ch);
case CompletionDataProviderKeyResult.InsertionKey:
return InsertSelectedItem(ch);
default:
@ -177,6 +182,20 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -177,6 +182,20 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
}
void DocumentAboutToBeChanged(object sender, DocumentEventArgs e)
{
// => startOffset test required so that this startOffset/endOffset are not incremented again
// for BeforeStartKey characters
if (e.Offset >= startOffset && e.Offset <= endOffset) {
if (e.Length > 0) { // length of removed region
endOffset -= e.Length;
}
if (!string.IsNullOrEmpty(e.Text)) {
endOffset += e.Text.Length;
}
}
}
protected override void CaretOffsetChanged(object sender, EventArgs e)
{
int offset = control.ActiveTextAreaControl.Caret.Offset;
@ -197,20 +216,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -197,20 +216,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
switch (keyData) {
case Keys.Back:
--endOffset;
if (endOffset < startOffset) {
Close();
}
return false;
case Keys.Delete:
if (control.ActiveTextAreaControl.Caret.Offset <= endOffset) {
--endOffset;
}
if (endOffset < startOffset) {
Close();
}
return false;
case Keys.Home:
codeCompletionListView.SelectIndex(0);
return true;
@ -247,18 +252,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -247,18 +252,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
control.ActiveTextAreaControl.TextArea.Focus();
}
protected override void OnClosed(EventArgs e)
protected override void Dispose(bool disposing)
{
base.OnClosed(e);
Dispose();
codeCompletionListView.Dispose();
codeCompletionListView = null;
declarationViewWindow.Dispose();
declarationViewWindow = null;
if (disposing) {
document.DocumentAboutToBeChanged -= DocumentAboutToBeChanged;
if (codeCompletionListView != null) {
codeCompletionListView.Dispose();
codeCompletionListView = null;
}
if (declarationViewWindow != null) {
declarationViewWindow.Dispose();
declarationViewWindow = null;
}
}
base.Dispose(disposing);
}
bool InsertSelectedItem(char ch)
{
document.DocumentAboutToBeChanged -= DocumentAboutToBeChanged;
ICompletionData data = codeCompletionListView.SelectedCompletionData;
bool result = false;
if (data != null) {

5
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/ICompletionDataProvider.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -45,7 +45,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
public enum CompletionDataProviderKeyResult
{
/// <summary>
/// Normal key, used to choose
/// Normal key, used to choose an entry from the completion list
/// </summary>
NormalKey,
/// <summary>
@ -54,7 +54,8 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -54,7 +54,8 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
InsertionKey,
/// <summary>
/// Increment both start and end offset of completion region when inserting this
/// key. Used to insert space.
/// key. Can be used to insert whitespace (or other characters) in front of the expression
/// while the completion window is open.
/// </summary>
BeforeStartKey
}

Loading…
Cancel
Save