Commit Graph

5518 Commits

Author SHA1 Message Date
Yee Cheng Chin
83e925e923 Support dictionary/data lookups of text
This adds support for looking up data under the mouse cursor. Usually it
will bring up a dictionary, but other times it could be a Wikipedia
article, Siri knowledge, etc. Apple doesn't really have a good name for
it, other than "looking up data", "quick look" (a confusingly similar
name with the other Quick Look OS feature), or "show definition". You
can activate this by doing Ctrl-Cmd-D when the mouse is over a cursor.
If you have a trackpad, you can also either activate this using Force
click or three-finger tap (depends on your system preference settings).

Note that for Force click, this could potentially make it impossible to
use the MacVim `<ForceClick>` mapping in Vim, which allows you to map a
force click to a Vim command (#716). This is handled by having a new
setting (under a new "Input" preference pane which will have more
populated later) that allows you to choose whether to use Force click
for data lookup or Vim's `<ForceClick>` mapping. If you have configured
to use three-finger taps though this setting wouldn't do anything, and
`<ForceClick>` is always send to the Vim mapping.

Also, this is lacking a lot of features that a normal macOS application
would get, e.g. looking up selected texts (e.g. if you have "ice cream",
you may want to select the whole thing to look up the phrase, rather
than just "ice" or "cream"), data detector, and much more (e.g. custom
API support). They will be done later as part of #1311.

Technical details below:

The way the OS knows how to look up the data and present it is by
talking to the NSTextInput/NSTextInputClient. Previously MacVim
implemented NSTextInput partially, and didn't implement the critical
firstRectForCharacterRange:actualRange and characterIndexForPoint:
functions. First, in this change we change from NSTextInput to
NSTextInputClient (which is the newer non-deprecated version), and
implement those functions, which allows the OS to query the text
storage.

By default, the OS sends a quickLookWithEvent: call to us whenever the
lookup happens but for some odd reason this isn't automatic for Force
clicks, presumably because some apps want to handle Force clicks
manually (this is why some apps only work for three-finger taps but not
Force clicks for lookups). This isn't documented but I found references
in iTerm/Firefox, and basically we just need to manually handle it and
send off quickLookWithEvent: when handling Force clicks.

For implementing the NSTextInputClient properly, the main issue is
making sure that can work properly with input methods / marked texts,
which is the other primary purpose for this class (other than inputting
keys). For data lookups, I'm representing the grid as a row-major text
(with no newline/space in between) and expose that to the OS. This
already has some issue because it doesn't handle Vim vertical splits
well, as MacVim doesn't really have access to detailed Vim text buffers
easily (unless we do a lot of calls back-and-forth). This means wrapped
texts won't be looked up properly, which I think is ok. Also, the OS
APIs deal with UTF-8 indices, so we can't just convert row/column to raw
indices and have to do a lot of character length calculations
(especially for wide chars like CJK or emojis) to make sure the returned
ranges are consistent and valid. For marked texts though, this presents
a challenge because Vim doesn't really have a strong enough API to
communicate back-and-forth about the marked positions and whatnot (it
only let the GUI know where the current cursor is), and it's hard to
implement APIs like `markedRange` properly because some marked texts
could be hidden or wrapped (if you implement some of these functions
improperly Apple's input methods could start misbehaving especially when
you use arrow keys to navigate). In the end I kept the original
implementation for treating the marked texts as a range starting from 0,
*only* when we have marked text. Kind of a hack but this makes sure we
work both in marked text mode (i.e. when inputting texts) and when doing
lookups. For simplicity I made it so that you can't do data lookups when
in marked text mode now.

Input method:

This change also fixes a quirk in input method as a driveby change.
Previously the logic for calculating the rect for where the candidate
list was quite broken, but now it's calculated correctly using the
desired range and the current cursor position. This matters when say
using Japanese IM and using the left/right arrow to jump to different
sections of the text. If the desired range is in a wrapped line, the new
logic would attempt to pin it to the left-most column of where the
cursor is in the range.

Data detection:

Note that the default implementation is quite bare, and lacks a lot of
smart data detection. For example, if you put your mouse over a URL, it
won't properly select the whole URL, and addresses and dates for example
also won't get grouped together properly. This is because these require
additional implementation (e.g. using NSDataDetector) instead of coming
"for free", and will be handled later. In fact, Apple's WebKit and
NSTextView cheats by calling an internal API framework called "Reveal"
(which you can find out by intercepting NSTextView's calls and/or
looking at WebKit's source code) which is much more powerful and
supports looking up package tracking, airline info, and more, but it's
not available to third-party software (that's why Safari's lookup is so
much better than Chrome/Firefox's).

This isn't tested right now. Future task needs to add XCTest support to
properly test this as there are a lot of edge cases involved here.

Fix #1191
Part of Epic #1311, which contains other items to be implemented.
2022-10-11 16:49:06 -07:00
Yee Cheng Chin
f8462bd3b4 Add File.Close support for terminal which also makes it work for Cmd-W
Since Vim upstream added support for `:confirm q` for terminals, we can
now get our File.Close menu to work properly for them as well. This also
means Cmd-W (which is bound to that menu item) works too.

Also just add validateMenuItem: for MMAppController even if we are just
returning YES. This makes it semantically clearer and is easier to
debug.
2022-10-09 13:20:47 -07:00
Yee Cheng Chin
09d44aa8c5 Merge remote-tracking branch 'vim/master' 2022-10-09 13:02:50 -07:00
Yee Cheng Chin
15b314ffbb patch 9.0.0708: :confirm does not work properly for a terminal buffer
Problem:    :confirm does not work properly for a terminal buffer.
Solution:   Handle :confirm for a terminal buffer differently.  (Yee Cheng
            Chin, closes #11312)
2022-10-09 18:53:32 +01:00
Yee Cheng Chin
89e86cc7e4 Update documentation to remove +sound from TODO
This was implemented in upstream Vim.
2022-10-08 11:37:22 -07:00
Yee Cheng Chin
996a256ed5 Merge remote-tracking branch 'vim/master' 2022-10-08 11:37:11 -07:00
Martin Tournoij
25f3a146a0 patch 9.0.0700: there is no real need for a "big" build
Problem:    There is no real need for a "big" build.
Solution:   Move common features to "normal" build, less often used features
            to the "huge" build. (Martin Tournoij, closes #11283)
2022-10-08 19:26:41 +01:00
Martin Tournoij
251c1e2ed8 patch 9.0.0698: VisVim is outdated, does not work with current Visual Studio
Problem:    VisVim is outdated, does not work with current Visual Studio.
Solution:   Remove VisVim. (Martin Tournoij)
2022-10-08 17:15:28 +01:00
Yee Cheng Chin
4314e4f7da patch 9.0.0694: no native sound support on Mac OS
Problem:    No native sound support on Mac OS.
Solution:   Add sound support for Mac OS. (Yee Cheng Chin, closes #11274)
2022-10-08 13:50:05 +01:00
ObserverOfTime
b7f52f5659 patch 9.0.0692: PoE filter files are not recognized
Problem:    PoE filter files are not recognized.
Solution:   Add a pattern to detect PoE filter files. (closes #11305)
2022-10-08 12:20:28 +01:00
Yee Cheng Chin
52dcad216b Add clearer documentation about how to query the system appearance mode
See #1306
2022-10-07 16:38:53 -07:00
Bram Moolenaar
bdc09a18fc patch 9.0.0683: cannot specify a time for :echowindow
Problem:    Cannot specify a time for :echowindow.
Solution:   A count can be used to specify the display time. Add
            popup_findecho().
2022-10-07 14:31:45 +01:00
Yee Cheng Chin
f1749a22cb Merge remote-tracking branch 'vim/master' 2022-10-06 15:33:20 -07:00
Bram Moolenaar
7beaf6a720 patch 9.0.0666: spacing-combining characters handled as composing
Problem:    Spacing-combining characters handled as composing, causing text to
            take more space than expected.
Solution:   Handle characters marked with "Mc" not as composing.
            (closes #11282
2022-10-05 18:03:00 +01:00
Bram Moolenaar
caf05f504e patch 9.0.0659: wrong type of comment in SetSyn() function
Problem:    Wrong type of comment in SetSyn() function.
Solution:   Use Vim9 comment. (closes #11278)
2022-10-04 18:42:10 +01:00
Martin Tournoij
7904fa420e patch 9.0.0657: too many #ifdefs
Problem:    Too many #ifdefs.
Solution:   Graduate the +cmdwin feature.  Now the tiny and small builds are
            equal, drop the small build.  (Martin Tournoij, closes #11268)
2022-10-04 16:28:45 +01:00
Bram Moolenaar
4ba5f1dab6 patch 9.0.0656: cannot specify another character to use instead of '@'
Problem:    Cannot specify another character to use instead of '@' at the end
            of the window.
Solution:   Add "lastline" to 'fillchars'. (Martin Tournoij, closes #11264,
            closes #10963)
2022-10-04 14:36:29 +01:00
Yee Cheng Chin
2499e5333a Merge remote-tracking branch 'vim/master' 2022-10-03 18:11:55 -07:00
Bram Moolenaar
f269eabc6c Update runtime files 2022-10-03 18:04:35 +01:00
Luuk van Baal
13ece2ae1d patch 9.0.0647: the 'splitscroll' option is not a good name
Problem:    The 'splitscroll' option is not a good name.
Solution:   Rename 'splitscroll' to 'splitkeep' and make it a string option,
            also supporting "topline". (Luuk van Baal, closes #11258)
2022-10-03 15:28:08 +01:00
Bram Moolenaar
f6196f4244 patch 9.0.0640: cannot scroll by screen line if a line wraps
Problem:    Cannot scroll by screen line if a line wraps.
Solution:   Add the 'smoothscroll' option.  Only works for CTRL-E and CTRL-Y
            so far.
2022-10-02 21:29:55 +01:00
Bram Moolenaar
a4e0b9785e patch 9.0.0634: evaluating "expr" options has more overhead than needed
Problem:    Evaluating "expr" options has more overhead than needed.
Solution:   Use call_simple_func() for 'foldtext', 'includeexpr', 'printexpr',
            "expr" of 'spellsuggest', 'diffexpr', 'patchexpr', 'balloonexpr',
            'formatexpr', 'indentexpr' and 'charconvert'.
2022-10-01 19:43:52 +01:00
Bram Moolenaar
87b4e5c5db patch 9.0.0632: calling a function from an "expr" option has overhead
Problem:    Calling a function from an "expr" option has too much overhead.
Solution:   Add call_simple_func() and use it for 'foldexpr'
2022-10-01 15:32:46 +01:00
Bram Moolenaar
9f573a8df0 patch 9.0.0622: matchaddpos() can get slow when adding many matches
Problem:    matchaddpos() can get slow when adding many matches.
Solution:   Update the next available match ID when manually picking an ID and
            remove check if the available ID can be used. (idea by Rick Howe)
2022-09-29 13:50:08 +01:00
Bram Moolenaar
50faf02f43 patch 9.0.0620: matchaddpos() can only add up to 8 matches
Problem:    matchaddpos() can only add up to 8 matches.
Solution:   Allocate the array of positions. (closes #11248)
2022-09-29 12:50:17 +01:00
Yee Cheng Chin
8cd33f3c43 Merge remote-tracking branch 'vim/master' 2022-09-28 16:54:05 -07:00
Bram Moolenaar
9fbdbb814f Update runtime files 2022-09-27 17:30:34 +01:00
ObserverOfTime
49c311c9b1 patch 9.0.0604: luacheckrc file is not recognized
Problem:    Luacheckrc file is not recognized.
Solution:   Use lua filetype for luacheckrc. (closes #11236)
2022-09-27 13:07:05 +01:00
rhysd
7fc6c0e4da patch 9.0.0602: new TypeScript extensions are not recognized
Problem:    New TypeScript extensions are not recognized.
Solution:   Recognize .mts and .cts files. (closes #11237)
2022-09-27 11:57:13 +01:00
ObserverOfTime
d324742292 patch 9.0.0600: GYP files are not recognized
Problem:    GYP files are not recognized.
Solution:   Recognize GYP files. (closes #11242)
2022-09-27 11:35:09 +01:00
ObserverOfTime
cde0319385 patch 9.0.0599: latexmkrc files are not recognized
Problem:    Latexmkrc files are not recognized.
Solution:   Use Perl filetype for latexmkrc files. (closes #11241)
2022-09-27 11:27:23 +01:00
Christian Brabandt
9882e9ddc9 patch 9.0.0587: Unicode tables are outdated
Problem:    Unicode tables are outdated.
Solution:   Update to Unicode release 15. (Christian Brabandt, closes #11220)
2022-09-25 19:25:51 +01:00
Bram Moolenaar
b9725bc7f6 patch 9.0.0583: only recognizing .m3u8 files is inconsistent
Problem:    Only recognizing .m3u8 files is inconsistent.
Solution:   Also matc .m3u files. (issue #11204)
2022-09-25 12:35:49 +01:00
Nbiba Bedis
9fd1583c83 patch 9.0.0566: Nim files are not recognized
Problem:    Nim files are not recognized.
Solution:   Add patterns for Nim files. (Nbiba Bedis, closes #11205)
2022-09-24 11:04:38 +01:00
=?UTF-8?q?Beno=C3=AEt=20Ryder?=
35fdd9a67d patch 9.0.0562: HSL playlist files are not recognized
Problem:    HSL playlist files are not recognized.
Solution:   Add a pattern to recognize HSL palylist files. (Benoît Ryder,
            closes #11204)
2022-09-23 20:33:39 +01:00
Bram Moolenaar
4cbdcbda2d patch 9.0.0524: build instructions for MS-Windows are outdated
Problem:    Build instructions for MS-Windows are outdated.
Solution:   Remove instructions for old MSVC versions.
2022-09-20 21:23:12 +01:00
ObserverOfTime
7c046ae99b patch 9.0.0510: Chatito files are not recognized
Problem:    Chatito files are not recognized.
Solution:   Add a pattern for Chatito files. (closes #11174)
2022-09-20 12:02:28 +01:00
Bram Moolenaar
9712ff1288 Update runtime files 2022-09-18 13:04:22 +01:00
ObserverOfTime
65ee49decf patch 9.0.0497: LyRiCs files are not recognized
Problem:    LyRiCs files are not recognized.
Solution:   Add a pattern to detect LyRiCs files. (closes #11155)
2022-09-18 12:46:22 +01:00
K.Takata
27b53be3a6 patch 9.0.0496: no good reason to keep supporting Windows-XP
Problem:    No good reason to keep supporting Windows-XP.
Solution:   Drop Windows-XP support. (Ken Takata, closes #11089)
2022-09-18 12:25:49 +01:00
Bram Moolenaar
73e28dcc61 patch 9.0.0491: no good reason to build without the float feature
Problem:    No good reason to build without the float feature.
Solution:   Remove configure check for float and "#ifdef FEAT_FLOAT".
2022-09-17 21:08:33 +01:00
Yee Cheng Chin
45b74e359d Merge remote-tracking branch 'vim/master' 2022-09-16 18:15:08 -07:00
Bram Moolenaar
1aea184a0d patch 9.0.0479: in :def function all closures in loop get the same variables
Problem:    In a :def function all closures in a loop get the same variables.
Solution:   Use a separate list of variables for LOADOUTER and SAVEOUTER.
2022-09-16 15:47:09 +01:00
Luuk van Baal
594f9e09cd patch 9.0.0478: test for 'splitscroll' takes too much time
Problem:    Test for 'splitscroll' takes too much time.
Solution:   Only test some of the combinations. (Luuk van Baal, closes #11139)
2022-09-16 12:52:58 +01:00
Bram Moolenaar
aa5341477c patch 9.0.0473: fullcommand() only works for the current script version
Problem:    fullcommand() only works for the current script version.
Solution:   Add an optional argument for the script version.
2022-09-15 21:46:02 +01:00
Yee Cheng Chin
c3c27f93ee Merge remote-tracking branch 'vim/master' 2022-09-13 21:11:40 -07:00
Bram Moolenaar
7b2d87220c Add missing part of patch 2022-09-12 15:16:29 +01:00
zeertzjq
cdc839353f patch 9.0.0449: there is no easy way to translate a key code into a string
Problem:    There is no easy way to translate a string with a key code into a
            readable string.
Solution:   Add the keytrans() function. (closes #11114)
2022-09-12 13:38:41 +01:00
ObserverOfTime
5a4eb55122 patch 9.0.0448: SubRip files are not recognized
Problem:    SubRip files are not recognized.
Solution:   Add a pattern for SubRip. (closes #11113)
2022-09-12 12:43:23 +01:00
Yee Cheng Chin
73f260832e Merge remote-tracking branch 'vim/master' 2022-09-12 01:01:41 -07:00