Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up TSFInputControl a bit #13677

Merged
merged 1 commit into from
Aug 8, 2022
Merged

Clean up TSFInputControl a bit #13677

merged 1 commit into from
Aug 8, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Aug 4, 2022

While working on #13398 I felt that TSFInputControl wasn't up to sniff.
This commit is a minor cleanup of the class:

  • default member initializers
  • Simplified use of STL classes which already perform boundary checks
  • Correctly check text buffer emptiness in _SendAndClearText
  • Track selection range as mandated by the API

Validation Steps Performed

  • Japanese IME (Full-Width Katakana)
    Typing "saitama" produces "サイタマ" ✅
  • Korean IME
    Typing "gksrmf" produces "한글" ✅
  • Vietnamese IME
    Typing "xin chaof" continues to produce broken "xin xinchaof"
    (It's supposed to produce "xin chào")
  • Emoji Picker (Win+.)

Comment on lines +74 to +75
_editContext.NotifyFocusEnter();
_focused = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in this class sets _editContext to nullptr. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Good point. We'll totally blow up in the ctor long before we get here.

Comment on lines -308 to -311
if (!_inputBuffer.empty())
{
_SendAndClearText();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_inputBuffer.empty() doesn't really matter. What matters is whether _activeTextStart == _inputBuffer.size(), because _activeTextStart indicates the actual start of the text we currently edit.

Comment on lines +377 to +378
// GH#5054: Pressing backspace might move the caret before the _activeTextStart.
_activeTextStart = ::base::ClampMin(_activeTextStart, ::base::ClampedNumeric<size_t>(range.StartCaretPosition));
Copy link
Member Author

@lhecker lhecker Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "some machines will fire [...]". As far as I can see all machines do that, but it depends on the circumstances. I've thus changed the comment to just be about backspacing.

@lhecker lhecker added the Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. label Aug 5, 2022
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth looking at the condensed git log for this file and making sure that previous bugs that were fixed are still fixed. FWIW. :)

@DHowett
Copy link
Member

DHowett commented Aug 5, 2022

nit: name in imperative style

remember: you have a stacked PR, don't bot-merge this!

@lhecker lhecker changed the title Partial cleanup of TSFInputControl Clean up TSFInputControl a bit Aug 5, 2022
_editContext.NotifyFocusLeave();
_editContext.NotifyTextChanged({ 0, bufLen }, 0, { 0, 0 });
_editContext.NotifyTextChanged({ 0, INT32_MAX }, 0, _selection);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does passing INT32_MAX here instead of _inputBuffer.length get us? Is there

Oh right we're clearing the buffer. Yea, blow away everything. makes sense.

const auto textRequested = _inputBuffer.substr(range.StartCaretPosition, length);

args.Request().Text(textRequested);
const auto range = args.Request().Range();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to clamp here anymore?

@DHowett DHowett merged commit 2c922e1 into main Aug 8, 2022
@DHowett DHowett deleted the dev/lhecker/tsf-cleanup branch August 8, 2022 18:51
ghost pushed a commit that referenced this pull request Aug 11, 2022
This commit builds directly on the changes made in #13677 and fixes:
* TSF resetting to AlphaNumeric ("ASCII") input mode when pressing enter
* Vietnamese IME not composing a new word after pressing whitespace, etc.

Closes #11479
Closes #13398

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" produces "xin chào" ✅
* Emoji Picker (Win+.)
  ✅
@ghost
Copy link

ghost commented Aug 17, 2022

🎉Windows Terminal Preview v1.15.228 has been released which incorporates this pull request.:tada:

Handy links:

PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request Oct 15, 2022
While working on microsoft#13398 I felt that `TSFInputControl` wasn't up to sniff.
This commit is a minor cleanup of the class:
* default member initializers
* Simplified use of STL classes which already perform boundary checks
* Correctly check text buffer emptiness in `_SendAndClearText`
* Track selection range as mandated by the API

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" continues to produce broken "xin xinchaof"
  (It's supposed to produce "xin chào")
* Emoji Picker (Win+.)
  ✅

(cherry picked from commit 2c922e1)
Service-Card-Id: 85034073
Service-Version: 1.15
PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request Oct 15, 2022
This commit builds directly on the changes made in microsoft#13677 and fixes:
* TSF resetting to AlphaNumeric ("ASCII") input mode when pressing enter
* Vietnamese IME not composing a new word after pressing whitespace, etc.

Closes microsoft#11479
Closes microsoft#13398

## Validation Steps Performed
* Japanese IME (Full-Width Katakana)
  Typing "saitama" produces "サイタマ" ✅
* Korean IME
  Typing "gksrmf" produces "한글" ✅
* Vietnamese IME
  Typing "xin chaof" produces "xin chào" ✅
* Emoji Picker (Win+.)
  ✅

(cherry picked from commit ed800dc)
Service-Card-Id: 84832470
Service-Version: 1.15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Automerge-Not-Compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants