Skip to content

Commit

Permalink
fix: autocomplete menu selection hack removed
Browse files Browse the repository at this point in the history
  • Loading branch information
PocketMiner82 committed Apr 20, 2024
1 parent 4a4af5c commit 556733c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pseudocodeIde/PseudocodeIDEForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ private void CodeTextBox_KeyDown(object sender, KeyEventArgs e)
e.SuppressKeyPress = TrySelectNextTabIndicator();
}

// hack to allow enter to autocomplete even if down wasnt pressed before
if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) && e.Modifiers == Keys.None && autoCompleteMenu.SelectedItemIndex < 0)
{
autoCompleteMenu.ProcessKey((char)Keys.Down, e.Modifiers);
}
//// hack to allow enter to autocomplete even if down wasnt pressed before
//if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) && e.Modifiers == Keys.None && autoCompleteMenu.SelectedItemIndex < 0)
//{
// autoCompleteMenu.ProcessKey((char)Keys.Down, e.Modifiers);
//}

// ignore CTRL[+SHIFT]+(Z/Y/L/R/E/S)
if ((e.KeyCode == Keys.Z || e.KeyCode == Keys.Y || e.KeyCode == Keys.L || e.KeyCode == Keys.R || e.KeyCode == Keys.E || e.KeyCode == Keys.S)
Expand Down
24 changes: 19 additions & 5 deletions pseudocodeIde/interpreter/pseudocode/PseudocodeAutocompleteItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AutocompleteMenuNS;
using pseudocodeIde;
using ScintillaNET;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -20,7 +21,7 @@ namespace pseudocode_ide.interpreter.pseudocode
/// <summary>
/// Represents an autocomplete item for pseudocode with custom behavior for replacing text.
/// </summary>
public class PseudocodeAutocompleteItem : SnippetAutocompleteItem
public class PseudocodeAutocompleteItem : AutocompleteItem
{
/// <summary>
/// Initializes a new instance of the <see cref="PseudocodeAutocompleteItem"/> class with the specified snippet and optional menu text.
Expand All @@ -29,10 +30,10 @@ public class PseudocodeAutocompleteItem : SnippetAutocompleteItem
/// <param name="menuText">The text to be displayed in the autocomplete menu. If null, the snippet is used.</param>
public PseudocodeAutocompleteItem(string snippet, string menuText = null) : base(snippet)
{
if (menuText != null)
{
MenuText = menuText;
}
Text = snippet.Replace("\r", "");
MenuText = menuText;
ToolTipText = snippet.Replace("^", "");
ToolTipTitle = "Snippet:";
}

/// <summary>
Expand Down Expand Up @@ -96,5 +97,18 @@ public override void OnSelected(SelectedEventArgs e)

PseudocodeIDEForm.Instance.AddTabSelectionIndicators(tabSelections);
}

/// <summary>
/// Compares fragment text with this item
/// </summary>
public override CompareResult Compare(string fragmentText)
{
return Text.StartsWith(fragmentText, StringComparison.InvariantCultureIgnoreCase) ? CompareResult.VisibleAndSelected : CompareResult.Hidden;
}

public override string ToString()
{
return MenuText ?? Text.Replace("\n", " ").Replace("^", "");
}
}
}

0 comments on commit 556733c

Please sign in to comment.