Skip to content

Commit 80a7ca9

Browse files
authored
Merge pull request #1312 from ychin/text-input-client-support-lookup
Support dictionary/data lookups of text
2 parents bb4c48a + 83e925e commit 80a7ca9

12 files changed

+558
-55
lines changed

runtime/doc/gui_mac.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ as general information regarding macOS user defaults.
259259
Here is a list of relevant dictionary entries:
260260

261261
KEY VALUE ~
262+
*MMAllowForceClickLookUp* use Force click for data lookup instead of
263+
<ForceClick> [bool]
262264
*MMCellWidthMultiplier* width of a normal glyph in em units [float]
263265
*MMCmdLineAlignBottom* Pin command-line to bottom of MacVim [bool]
264266
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
@@ -783,11 +785,17 @@ Each gesture generates one of the following Vim pseudo keys:
783785

784786
*<SwipeUp>* *<SwipeDown>*
785787
Generated when swiping three fingers across the trackpad in a
786-
vertical direction. (Not supported by the Apple Magic Mouse.)
788+
vertical direction. (Not supported by the Apple Magic Mouse)
787789

788790
*<ForceClick>*
789791
Generated when doing a Force click by pressing hard on a trackpad.
790-
(Only supported on trackpads that support Force Touch.)
792+
(Only supported on trackpads that support Force Touch)
793+
794+
If you have configured to use Force click for "Look up & data
795+
detectors" in the system settings, by default MacVim will do a
796+
dictionary lookup instead of triggering this mapping. You can turn
797+
this off in MacVim's Preference pane, or directly set
798+
|MMAllowForceClickLookUp|.
791799

792800
You can map these keys like with any other key using the |:map| family of
793801
commands. For example, the following commands map left/right swipe to change

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5417,6 +5417,7 @@ LogiPat-flags pi_logipat.txt /*LogiPat-flags*
54175417
Lua if_lua.txt /*Lua*
54185418
M motion.txt /*M*
54195419
MDI starting.txt /*MDI*
5420+
MMAllowForceClickLookUp gui_mac.txt /*MMAllowForceClickLookUp*
54205421
MMAppearanceModeSelection gui_mac.txt /*MMAppearanceModeSelection*
54215422
MMCellWidthMultiplier gui_mac.txt /*MMCellWidthMultiplier*
54225423
MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
<customObject id="-2" userLabel="File's Owner" customClass="MMPreferenceController">
1010
<connections>
1111
<outlet property="advancedPreferences" destination="620" id="632"/>
12+
<outlet property="allowForceClickLookUpButton" destination="rlt-zw-mfW" id="xCv-HS-zyJ"/>
1213
<outlet property="appearancePreferences" destination="hr4-G4-3ZG" id="G54-DD-ACh"/>
1314
<outlet property="autoInstallUpdateButton" destination="UYM-W0-Kgl" id="cX5-tk-9WJ"/>
1415
<outlet property="generalPreferences" destination="115" id="143"/>
16+
<outlet property="inputPreferences" destination="Bnq-Nx-GJH" id="FES-rQ-Fpa"/>
1517
<outlet property="layoutPopUpButton" destination="427" id="596"/>
1618
<outlet property="sparkleUpdaterPane" destination="0hT-y8-Hge" id="e0L-sv-OCW"/>
1719
</connections>
@@ -475,6 +477,40 @@
475477
</subviews>
476478
<point key="canvasLocation" x="137.5" y="435"/>
477479
</customView>
480+
<customView id="Bnq-Nx-GJH" userLabel="Input">
481+
<rect key="frame" x="0.0" y="0.0" width="483" height="58"/>
482+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
483+
<subviews>
484+
<customView id="DAP-Yi-QU0" userLabel="Trackpad">
485+
<rect key="frame" x="20" y="20" width="433" height="18"/>
486+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
487+
<subviews>
488+
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="f18-Wr-EgZ">
489+
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
490+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
491+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Trackpad:" id="jkp-Ls-ZhN">
492+
<font key="font" metaFont="system"/>
493+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
494+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
495+
</textFieldCell>
496+
</textField>
497+
<button id="rlt-zw-mfW" userLabel="Force click option">
498+
<rect key="frame" x="189" y="-1" width="213" height="18"/>
499+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
500+
<string key="toolTip">Allow Force clicks to look up data when it is configured to do so (under "Trackpad" in System Settings). This will prevent &lt;ForceClick&gt; mappings in Vim from working. If you rely on &lt;ForceClick&gt; mappings, you may want to unset this option. This setting does not matter if you have configured to use three-finger taps to look up instead, as &lt;ForceClick&gt; will always work.</string>
501+
<buttonCell key="cell" type="check" title="Use Force click to look up data" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="A5o-Il-XdJ" userLabel="Force click option">
502+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
503+
<font key="font" metaFont="system"/>
504+
</buttonCell>
505+
<connections>
506+
<binding destination="58" name="value" keyPath="values.MMAllowForceClickLookUp" id="sef-c3-KyZ"/>
507+
</connections>
508+
</button>
509+
</subviews>
510+
</customView>
511+
</subviews>
512+
<point key="canvasLocation" x="137.5" y="679"/>
513+
</customView>
478514
<customView id="620" userLabel="Advanced">
479515
<rect key="frame" x="0.0" y="0.0" width="483" height="264"/>
480516
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>

src/MacVim/MMAppController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ + (void)initialize
256256
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
257257
[NSNumber numberWithBool:NO], MMSmoothResizeKey,
258258
[NSNumber numberWithBool:NO], MMCmdLineAlignBottomKey,
259+
[NSNumber numberWithBool:YES], MMAllowForceClickLookUpKey,
259260
nil];
260261

261262
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];

src/MacVim/MMCoreTextView.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@
1313
@class MMTextViewHelper;
1414

1515

16+
/// The main text view that manages drawing Vim's content using Core Text, and
17+
/// handles input. We are using this instead of NSTextView because of the
18+
/// custom needs in order to draw Vim's texts, as we don't have access to the
19+
/// full contents of Vim, and works more like a smart terminal to Vim.
20+
///
21+
/// Currently the rendering is done in software via Core Text, but a future
22+
/// extension will add support for Metal rendering which probably will require
23+
/// splitting this class up.
24+
///
25+
/// Since this class implements text rendering/input using a custom view, it
26+
/// implements NSTextInputClient, mostly for the following needs:
27+
/// 1. Text input. This is done via insertText / doCommandBySelector.
28+
/// 2. Input methods (e.g. for CJK). This is done via the marked text and the
29+
/// other APIs like selectedRange/firstRectForCharacterRange/etc.
30+
/// 3. Support native dictionary lookup (quickLookWithEvent:) when the user
31+
/// wants to. This mostly involves implementing the attributeSubstring /
32+
/// firstRectForCharacterRange / characterIndexForPoint APIs.
33+
/// There is an inherent difficulty to implementing NSTextInputClient
34+
/// 'correctly', because it assumes we have an entire text storage with
35+
/// indexable ranges. However, we don't have full access to Vim's internal
36+
/// storage, and we are represening the screen view instead in row-major
37+
/// indexing, but this becomes complicated when we want to implement marked
38+
/// texts. We the relevant parts for comments on how we hack around this.
1639
@interface MMCoreTextView : NSView <
17-
NSTextInput
40+
NSTextInputClient
1841
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
1942
, NSFontChanging
2043
, NSMenuItemValidation
@@ -122,8 +145,21 @@
122145
// NSTextView methods
123146
//
124147
- (void)keyDown:(NSEvent *)event;
125-
- (void)insertText:(id)string;
148+
149+
//
150+
// NSTextInputClient methods
151+
//
152+
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange;
126153
- (void)doCommandBySelector:(SEL)selector;
154+
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange;
155+
- (void)unmarkText;
156+
- (NSRange)selectedRange;
157+
- (NSRange)markedRange;
158+
- (BOOL)hasMarkedText;
159+
- (nullable NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange;
160+
- (nonnull NSArray<NSAttributedStringKey> *)validAttributesForMarkedText;
161+
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange;
162+
- (NSUInteger)characterIndexForPoint:(NSPoint)point;
127163

128164
//
129165
// NSTextContainer methods

0 commit comments

Comments
 (0)