Comments (7)
Also, I goofed and misnamed the branch here. That just adds to the confusion.
from terminal.gui.
If no Accept event hanlder is set, TextView works properly:
[Theory]
[InlineData (true, 0)]
[InlineData (false, 1)]
public void Accept_No_Handler_Enables_Default_Button_Accept (bool multiline, int expectedButtonAccept)
{
var superView = new Window ();
var tv = new TextView ()
{
Multiline = multiline
};
var button = new Button ()
{
IsDefault = true,
};
superView.Add (tv, button);
var buttonAccept = 0;
button.Accept += ButtonAccept;
tv.SetFocus ();
Assert.True (tv.HasFocus);
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (expectedButtonAccept, buttonAccept);
button.SetFocus ();
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (expectedButtonAccept + 1, buttonAccept);
return;
void ButtonAccept (object sender, CancelEventArgs e)
{
buttonAccept++;
}
}
This new test fails. I'll fix.
[Theory]
[InlineData (false, false, 0)]
[InlineData (false, true, 1)]
public void Accept_Handler_Cancel_Prevents_Default_Button_Accept (bool multiline, bool cancelAccept, int expectedButtonAccepts)
{
var superView = new Window ();
var tv = new TextView ()
{
Multiline = multiline
};
var button = new Button ()
{
IsDefault = true,
};
superView.Add (tv, button);
var buttonAccept = 0;
button.Accept += ButtonAccept;
var textViewAccept = 0;
tv.Accept += TextViewAccept;
tv.SetFocus ();
Assert.True (tv.HasFocus);
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (1, textViewAccept);
Assert.Equal (expectedButtonAccepts, buttonAccept);
button.SetFocus ();
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (1, textViewAccept);
Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
return;
void TextViewAccept (object sender, CancelEventArgs e)
{
textViewAccept++;
e.Cancel = cancelAccept;
}
void ButtonAccept (object sender, CancelEventArgs e)
{
buttonAccept++;
}
}
from terminal.gui.
This defines the correct behavior, I think...
[Theory]
[InlineData (false, 0)]
[InlineData (true, 1)]
public void Accept_Handler_Cancel_Prevents_Default_Button_Accept (bool cancelAccept, int expectedButtonAccepts)
{
var superView = new Window ();
var tf = new TextField ();
var button = new Button ()
{
IsDefault = true,
};
superView.Add (tf, button);
var buttonAccept = 0;
button.Accept += ButtonAccept;
var textFieldAccept = 0;
tf.Accept += TextFieldAccept;
tf.SetFocus ();
Assert.True (tf.HasFocus);
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (1, textFieldAccept);
Assert.Equal (expectedButtonAccepts, buttonAccept);
button.SetFocus ();
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (1, textFieldAccept);
Assert.Equal (expectedButtonAccepts + 1, buttonAccept);
return;
void TextFieldAccept (object sender, CancelEventArgs e)
{
textFieldAccept++;
e.Cancel = cancelAccept;
}
void ButtonAccept (object sender, CancelEventArgs e)
{
buttonAccept++;
}
}
[Fact]
public void Accept_No_Handler_Enables_Default_Button_Accept ()
{
var superView = new Window ();
var tf = new TextField ();
var button = new Button ()
{
IsDefault = true,
};
superView.Add (tf, button);
var buttonAccept = 0;
button.Accept += ButtonAccept;
tf.SetFocus ();
Assert.True (tf.HasFocus);
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (1, buttonAccept);
button.SetFocus ();
superView.NewKeyDownEvent (Key.Enter);
Assert.Equal (2, buttonAccept);
return;
void ButtonAccept (object sender, CancelEventArgs e)
{
buttonAccept++;
}
}
The bug is View.OnAccept
should return null if there's no event handler and TextField
should do this:
AddCommand (Command.Accept, () => OnAccept () == false);
from terminal.gui.
@tig sorry for my confusion. TextView
contains the Multiline
property and not the TextField
. If you use a TextView
with Multiline
as true and with focus, then the Enter
key must be manipulated by the TextView
and not by the button, right?
from terminal.gui.
@tig sorry for my confusion.
TextView
contains theMultiline
property and not theTextField
. If you use aTextView
withMultiline
as true and with focus, then theEnter
key must be manipulated by theTextView
and not by the button, right?
I think so.
But if textView.MultiLine == false
, shouldn't it behave just like a TextField
in this regard?
from terminal.gui.
I think so.
But if
textView.MultiLine == false
, shouldn't it behave just like aTextField
in this regard?
Yes, in this case return false for the default button to process it.
from terminal.gui.
Also, I goofed and misnamed the branch here. That just adds to the confusion.
It was also my fault for confusing TextField
with TextView
, sorry. What matters is that it is corrected in the code and does not include the name of the branch or title. Furthermore, TextField
was also improperly handling Accept
.
from terminal.gui.
Related Issues (20)
- Automate getting cultures from the embedded resources strings for self-contained app.
- Focus gets confused with `ContextMenu`. HOT 1
- Overlapped broken on the v2_develop branch using the BackgroundWorkerCollection scenario. HOT 7
- Checked renamed State in CheckBox HOT 10
- Some uses of the `CheckStyle` enum are buggy
- `ShadowStyle.Transparent` is not rendering bottom-left corner correctly
- TGD: Master Issue tracking TG issues that must be fixed in v2 HOT 21
- Ensure `OCGV` is working
- Setting `Menus` causes unexpected Exception HOT 13
- Ctrl-Q Closes Application HOT 8
- v2: Keyboard navigation on MessageBox no longer working HOT 3
- V2 crashes under Git For Windows bash session
- AppendAutocomplete not rendering correctly (v2)
- Shortcut crashes when removed from SuperView and ColorScheme set to null HOT 1
- Running Application.Begin sometimes crashes on keybindings HOT 11
- Null reference in v2 in FindDeepestView HOT 4
- Proposal: Focus/Navigation Changes - e.g. Remove `Tabindex` and `TabIndexes` in v2 HOT 8
- Using emoji HOT 3
- Mac Error - Error opening terminal: unknown. HOT 4
- NativeAot project isn't using the correct release nuget package.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminal.gui.