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

Scroll from selection dragging out of window (#1247) #1523

Merged
merged 88 commits into from
Jul 24, 2019

Conversation

mcpiroman
Copy link
Contributor

Summary of the Pull Request

When user is mouse selecting and cursor wents out of viewport, terminal now scrolls down or up to 'follow' the cursor and expands selection. Additionally, when scrolling with mouse wheel while selecting, selection now updates immediately (instead of on next mouse move event).

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Scrolling occures smoothly, i.e. you don't have to 'wave' the mouse to speed up scrolling as it is in conhost. The speed of scroll is determined by quadratic function. I tried to immitiate the browser's behaviour.
  • Scrollbar update occures at fixed 30 times/sec interval and is handled by DispatcherTimer. Idk if it's prefered solution but I'm not aware of better one.

Validation steps

  • Overfill visible buffer.
  • Start selection and move cursor below and above window, at diffrenet distances.
  • Start selection and scroll by mouse wheel without moving cursor.

@carlos-zamora carlos-zamora self-requested a review June 24, 2019 10:46
const short lastVisibleCol = std::max(_terminal->GetViewport().Width() - 1, 0);

terminalPosition.Y = std::clamp(terminalPosition.Y, short{ 0 }, lastVisibleRow);
terminalPosition.X = std::clamp(terminalPosition.X, short{ 0 }, lastVisibleCol);
Copy link
Member

@carlos-zamora carlos-zamora Jun 25, 2019

Choose a reason for hiding this comment

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

Check out Viewport::Clamp(). Is there a way we could use that here? #Resolved

Copy link
Contributor Author

@mcpiroman mcpiroman Jun 26, 2019

Choose a reason for hiding this comment

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

Viewport::Clamp() expects absolute position, whereas src and dst of terminalPosition are relative to scroll offset. #Resolved

{
if (_autoScrollVelocity != 0)
{
_scrollBar.Value(_scrollBar.Value() + _autoScrollVelocity * _AutoScrollTimerInterval);
Copy link
Member

@carlos-zamora carlos-zamora Jun 25, 2019

Choose a reason for hiding this comment

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

I just want to say. I understand this because of Physics class and I never thought that moment would come. #Resolved

Copy link
Contributor Author

@mcpiroman mcpiroman Jun 25, 2019

Choose a reason for hiding this comment

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

Just everyday snippet at gamedev :) #Resolved


if (_terminal->IsSelectionActive() && pointerPoint.Properties().IsLeftButtonPressed())
{
// If user is mouse selecting and scrolls, he then points at new character.
Copy link
Member

@carlos-zamora carlos-zamora Jun 25, 2019

Choose a reason for hiding this comment

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

Suggested change
// If user is mouse selecting and scrolls, he then points at new character.
// If user is mouse selecting and scrolls, they then point at new character.
``` #Resolved

Copy link
Contributor Author

@mcpiroman mcpiroman Jun 25, 2019

Choose a reason for hiding this comment

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

Is this how do you write that? Well, understand the sad purpose of this, but it doesn't seem grammatically correct. #Resolved

Copy link
Member

@carlos-zamora carlos-zamora Jun 26, 2019

Choose a reason for hiding this comment

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

I agree it sounds weird; guess I just got used to it. It's one of the ways I learned it and it's generally pretty easy to incorporate. #Resolved

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

This is awesome. Thank you so much!

@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jun 25, 2019
@mcpiroman
Copy link
Contributor Author

mcpiroman commented Jun 26, 2019

I've changed _UpdateAutoScroll to base on real time delta instead of the target one. This makes it behave better if the target one can't be met. Also separated the related logic to functions. #Resolved

@carlos-zamora
Copy link
Member

Looks like you need to run Invoke-CodeFormat on your branch. Re-running the CI because it said "tests failed" but this shouldn't be affecting the tests that failed.

@mcpiroman

This comment has been minimized.

@mcpiroman
Copy link
Contributor Author

Ok that helped

@mcpiroman
Copy link
Contributor Author

Actually, the middle-mouse-button (panning) scroll could be implemented using the same mechanism, unless there is a better way to do this (like the wierd function that conhost uses). Is there?

@carlos-zamora
Copy link
Member

Actually, the middle-mouse-button (panning) scroll could be implemented using the same mechanism, unless there is a better way to do this (like the wierd function that conhost uses). Is there?

Huh. I didn't even realize that conhost had that feature until just now. I think if we add it in though, we'd want some kind of visual cue (as in ConHost now) over the cursor. Feel free to create a Feature Request on this.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm only really blocking on the Close thing, the others feel more like nits to me.

src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/TermControl.cpp Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 2, 2019
lhecker and others added 2 commits July 23, 2019 20:47
This commit changes how TerminalControl/TerminalCore handle key events to give it better knowledge about modifier states at the lower levels.
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 23, 2019
@mcpiroman
Copy link
Contributor Author

I cant stand this merging..

carlos-zamora and others added 10 commits July 23, 2019 21:33
* Connects clipboard functionality to their keybindings.

* Cleaning up comments and whitespace.

* Added "copyTextWithoutNewlines" keybinding.

* Fixing tabs in idl file

* Fixing merge conflicts

* Adding default keybindings for copy and paste to ctrl-shift-c and ctrl-shift-v, respectively.

* Complying with refactoring

* Fixing formatting issues
…ith a single Island (microsoft#929)

* Use a region to cut off the dragable region
* Use proper measurements for the draggable area
* Working better, paint works most of the time
* Fix a bug where paint is incomplete when double clicking the dragbar
* Remove old fork on XamlApplication
* Upgrade to XamlApp preview6.2
* Add Microsoft.VCRTForwarders to make it easy to dogfood

Co-Authored-By: Michael Niksa <miniksa@microsoft.com>
Co-Authored-By: Mike Griese <migrie@microsoft.com>
…osoft#1012)

* move version to vs2019, the 1903 sdk, and the 14.2 build tools.
…t#1676)

* App now initializes the connection instead of term control.
* Refactors TerminalApp into two projects: 
  - TerminalAppLib, which builds a .lib, and includes all the code
  - TerminalApp, which builds a dll by linking the lib
* Adds a TerminalApp.Unit.Tests project
  - Includes the ability to test cppwinrt types we've authored using a SxS manifest for unpackaged winrt activation
  - includes the ability to test types with XAML content using an appxmanifest
* Adds a giant doc explaining how this was all done. Really, just go read that doc, it'll really help you understand what's going on in this PR.

-------------------------
These are some previous commit messages. They may be helpful to future readers.

* Start adding unittests for json parsing, end up creating a TerminalAppLib project to make a lib. See microsoft#1042

* VS automatically did this for me

* This is a dead end

  I tried including the idl-y things into the lib, but that way leads insanity

  If you want to make a StaticLibrary, then suddenly the winrt toolchain forgets
  that ProjectReferences can have winmd's in them, so it won't be able to
  compile any types from the referenced projects. If you instead try to manually
  reference the types, you'll get duplicate types up the wazoo, which of course
  is insane, since we're referencing them the _one_ time

* Yea just follow microsoft#1042 on github for status

  So current state:

  1. If you try to add a `Reference` to all of MUX.Markup, TerminalControl and
     TerminalSettings, then mdmerge will complain about all   the types from
     TerminalSettings being defined twice. In this magic scenario, the
     dependencies of TerminalControl are used directly   for some reason:

```
  12>    Load input metadata file ...OpenConsole\x64\Debug\TerminalSettings\Microsoft.Terminal.Settings.winmd.
  12>    Load input metadata file ...OpenConsole\x64\Debug\TerminalControl\Microsoft.Terminal.Settings.winmd.
  12>    Load input metadata file ...OpenConsole\x64\Debug\TerminalControl\Microsoft.Terminal.TerminalConnection.winmd.
  12>    Load input metadata file ...OpenConsole\x64\Debug\TerminalControl\Microsoft.Terminal.TerminalControl.winmd.
  12>    Load input metadata file ...OpenConsole\x64\Debug\Microsoft.UI.Xaml.Markup\Microsoft.UI.Xaml.Markup.winmd.
```

  2. If you don't add a `Reference` TerminalControl, then it'll complain about
     being unable to find the type TitleChangedEventArgs,   which is defined in
     TerminalControl.

  3. If you don't add a `Reference` TerminalSettings, then it'll complain about
     being unable to find the type KeyChord and other   types from
     TerminalSettings. In this scenario, it doesn't recurse on the other
     dependencies from TerminalControl for whatever   reason.

  4. If you instead try to add all 3 as a `ProjectReference`, then it'll
     complain about being unable to find TitleChangedEventArgs,   as in 2.
     Presumably, it;ll have troubles with the other types too, as none of the 3
     are actually included in the midlrt.rsp file.

  5. If you add all 3 as a `ProjectReference`, then also add TerminalControl as
     a `Reference`, you'll get a `MIDL2011: [msg]  unresolved type declaration
     Microsoft.UI.Xaml.Markup.XamlApplication`

  6. If you add all 3 as a `ProjectReference`, then also add TerminalControl AND
     MUX.Markup as a `Reference`, you'll get the same   result as 3.

* what if we just don't idl

  This seems to compile

* This compiles but I broke the MUX resources

  look at the App.xaml change. in this changelist. That's what's broken right now. Lets fix that!

* lets do this

    If I leave the MUX nuget out of the project, I'll get a compile error in
    App.xaml:

    ```
    ...OpenConsole\src\cascadia\TerminalApp\App.xaml(21,40): XamlCompiler error WMC0001: Unknown type 'XamlControlsResources' in XML namespace 'using:Microsoft.UI.Xaml.Controls'
    ```

    If I add it back to the project, it works

* Some cleanup from the previous commit

* This is busted again.

  Doing a clean build didn't work.

    A clean rebuild of the project, paired with some removal of dead code
    revealed a problem with what I have so far.

    TerminalAppLib depends on the generation of two headers,
    `AppKeyBindings.g.h` and `App.g.h`, as those define some of bits of the
    winrt types. They're needed to be able to compile the implementations.
    Presumably that's not getting generated by the lib project, because the dll
    project is the one to generate that file.

    So we need to move the idl's to the lib project. This created maddness,
    because of course the Duplicate Type thing. The solution to that is to
    actually mark the winrt DLLs that we're chaining up through us as

    ```
        <Private>false</Private>
        <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
    ```

    This will prevent them from getting double-included.

    This still doesn't work however, since
    ```
    app.cpp(40): error C2039: 'XamlMetaDataProvider': is not a member of 'winrt::TerminalApp'
    error C3861: 'XamlMetaDataProvider': identifier not found
    ```

    So we need to figure that out. The dll project is still generating the right
    header, so lets look there.

* Move the xaml stuff to the lib

  This compiles, but when we launch, we fail to load the tabviewcontrol
  resources again. So that's not what you want. Why is it not included?

* It works again!

  * Use the pri, xbf files from TerminalAppLib, not TerminalApp
  * Manually make TerminalApp include a reference to TerminalAppLib's
    TerminalApp.winmd. This will force the build to copy TerminalApp.winmd to
    TerminalApp/, which WindowsTerminal needs to be able to ProjectReference the
    TerminalApp project (it's expecting it to have a winmd)
  * Remove the module.g.cpp from TerminalApp, and move to TerminalAppLib. The
    dll doesn't do any codegen anymore.

* Agressively clean up these files

* Clean up unnecessary includes in the dll pch.h

* This does NOT work.

  The WindowsxamlManager call crashes. I'm thinking it has to do with activation
  of winrt types from a dll.

  Email out to @Austin-Lamb to see if he can assist

* This gets our cppwinrt types working, but xaml islands is still broken

* Split the tests apart, so they aren't insane

* These are the magic words to make xaml islands work

* All this witchcraft is necessary to make XAML+MUX work right

* Clean this up a bit and add comments

* Create an enormous doc explaining this madness

* Unsure how this got changed.

* Trying to get the CI build to work again.

  This resolves the MUX issue. We need to manually include it, because their package's target doesn't mark it as CopyLocalSatelliteAssemblies=false, Private=false.

  However, the TerminalApp project is still able to magically reason that the TerminalAppLib project should be included in the MdMerge step, because it think's it's a `GetCppWinRTStaticProjectReferences` reference.

* Update cppwinrt to the latest version - this fixes the MSBuild

  * I still need to re-add the KeyModifiers checks from TermControl. I think
    this update broke `operator&` for that enum.
  * There needs to be some cleanup obviously
  * The doc should be updated as well

* Clean up changes from cppwinrt update

* Try doing this, even though it seems wrong

* Lets try this (press x to doubt)

* Clean up vcxproj file, and remove appxmanifest change from previous commit

* Update to the latest TAEF release, maybe that'll work

* Let's try a prerelease version, shall we?

* Add notes about TAEF package, comment out tests

* Format the code

* Hopefully fix the arm64 and x86 builds

  also a typo

* Fix PR nits

* Fix some bad merge conflicts

* Some cleanup from the merge

* Well I was close to getting the merge right

* I believe this will fix CI

* Apply suggestions from code review

Co-Authored-By: Carlos Zamora <carlos.zamora@microsoft.com>

* These definitely need to be fixed

* Try version detecting in the test

  IDK if this will build, I'm letting the CI try while I clean rebuild locally

* Try blindly updating to the newest nuget version

* Revert "Try blindly updating to the newest nuget version"

This reverts commit b72bd9e.

* We're just going to see if these work in CI with this change

* Comment the tests back out. Windows Server 2019 is 10.0.17763.557

* Remove the nuget package

  We don't need this package anymore now that we're hosting it

* Okay this _was_ important
@miniksa
Copy link
Member

miniksa commented Jul 23, 2019

I cant stand this merging..

Rebase?

@mcpiroman
Copy link
Contributor Author

mcpiroman commented Jul 23, 2019

Rebase by the means of merging master onto branch. Or whatever. I must now do this by hand since Visual Studio's Git plugin turned out to be untrustworthy. After resolving the same conflicts few times, resolving totally unrelated conflicts, crash, and when everything looked ok, then this happend. Fortunetly there isn't much going on in this PR. Sorry for problems.

@miniksa
Copy link
Member

miniksa commented Jul 23, 2019

Rebase by the means of merging master onto branch. Or whatever. I must now do this by hand since Visual Studio's Git plugin turned out to be untrustworthy. After resolving the same conflicts few times, resolving totally unrelated conflicts, crash, and when everything looked ok, then this happend.

Sorry. I always do this with git commands at the command line, not with the Visual Studio plugin. I've been burned by it before too. Apologies. :(

@DHowett-MSFT
Copy link
Contributor

Good word github did a number on this

@mcpiroman
Copy link
Contributor Author

Yea, now it's one of the biggest PRs ever.
And as winrt:: things are nullable, then why is _cursorTimer made optional 🤔

@mcpiroman
Copy link
Contributor Author

mcpiroman commented Jul 23, 2019

Finally!
Just in time before just merged pr screwed things again.
Ah yeah, formatting

@miniksa
Copy link
Member

miniksa commented Jul 24, 2019

OK @mcpiroman, I'll save you from more misery here and get it merged. Thank you for bearing with all of that.

@miniksa miniksa merged commit 5da2ab1 into microsoft:master Jul 24, 2019
@ghost
Copy link

ghost commented Aug 3, 2019

🎉Windows Terminal Preview v0.3.2142.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Scroll from selection dragging out of window