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

Support dictionary/data lookups of text #1312

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ as general information regarding macOS user defaults.
Here is a list of relevant dictionary entries:

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

*<SwipeUp>* *<SwipeDown>*
Generated when swiping three fingers across the trackpad in a
vertical direction. (Not supported by the Apple Magic Mouse.)
vertical direction. (Not supported by the Apple Magic Mouse)

*<ForceClick>*
Generated when doing a Force click by pressing hard on a trackpad.
(Only supported on trackpads that support Force Touch.)
(Only supported on trackpads that support Force Touch)

If you have configured to use Force click for "Look up & data
detectors" in the system settings, by default MacVim will do a
dictionary lookup instead of triggering this mapping. You can turn
this off in MacVim's Preference pane, or directly set
|MMAllowForceClickLookUp|.

You can map these keys like with any other key using the |:map| family of
commands. For example, the following commands map left/right swipe to change
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -5417,6 +5417,7 @@ LogiPat-flags pi_logipat.txt /*LogiPat-flags*
Lua if_lua.txt /*Lua*
M motion.txt /*M*
MDI starting.txt /*MDI*
MMAllowForceClickLookUp gui_mac.txt /*MMAllowForceClickLookUp*
MMAppearanceModeSelection gui_mac.txt /*MMAppearanceModeSelection*
MMCellWidthMultiplier gui_mac.txt /*MMCellWidthMultiplier*
MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*
Expand Down
36 changes: 36 additions & 0 deletions src/MacVim/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
<customObject id="-2" userLabel="File's Owner" customClass="MMPreferenceController">
<connections>
<outlet property="advancedPreferences" destination="620" id="632"/>
<outlet property="allowForceClickLookUpButton" destination="rlt-zw-mfW" id="xCv-HS-zyJ"/>
<outlet property="appearancePreferences" destination="hr4-G4-3ZG" id="G54-DD-ACh"/>
<outlet property="autoInstallUpdateButton" destination="UYM-W0-Kgl" id="cX5-tk-9WJ"/>
<outlet property="generalPreferences" destination="115" id="143"/>
<outlet property="inputPreferences" destination="Bnq-Nx-GJH" id="FES-rQ-Fpa"/>
<outlet property="layoutPopUpButton" destination="427" id="596"/>
<outlet property="sparkleUpdaterPane" destination="0hT-y8-Hge" id="e0L-sv-OCW"/>
</connections>
Expand Down Expand Up @@ -475,6 +477,40 @@
</subviews>
<point key="canvasLocation" x="137.5" y="435"/>
</customView>
<customView id="Bnq-Nx-GJH" userLabel="Input">
<rect key="frame" x="0.0" y="0.0" width="483" height="58"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="DAP-Yi-QU0" userLabel="Trackpad">
<rect key="frame" x="20" y="20" width="433" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="f18-Wr-EgZ">
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Trackpad:" id="jkp-Ls-ZhN">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button id="rlt-zw-mfW" userLabel="Force click option">
<rect key="frame" x="189" y="-1" width="213" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<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>
<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">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="58" name="value" keyPath="values.MMAllowForceClickLookUp" id="sef-c3-KyZ"/>
</connections>
</button>
</subviews>
</customView>
</subviews>
<point key="canvasLocation" x="137.5" y="679"/>
</customView>
<customView id="620" userLabel="Advanced">
<rect key="frame" x="0.0" y="0.0" width="483" height="264"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ + (void)initialize
[NSNumber numberWithBool:YES], MMShareFindPboardKey,
[NSNumber numberWithBool:NO], MMSmoothResizeKey,
[NSNumber numberWithBool:NO], MMCmdLineAlignBottomKey,
[NSNumber numberWithBool:YES], MMAllowForceClickLookUpKey,
nil];

[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
Expand Down
40 changes: 38 additions & 2 deletions src/MacVim/MMCoreTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@
@class MMTextViewHelper;


/// The main text view that manages drawing Vim's content using Core Text, and
/// handles input. We are using this instead of NSTextView because of the
/// custom needs in order to draw Vim's texts, as we don't have access to the
/// full contents of Vim, and works more like a smart terminal to Vim.
///
/// Currently the rendering is done in software via Core Text, but a future
/// extension will add support for Metal rendering which probably will require
/// splitting this class up.
///
/// Since this class implements text rendering/input using a custom view, it
/// implements NSTextInputClient, mostly for the following needs:
/// 1. Text input. This is done via insertText / doCommandBySelector.
/// 2. Input methods (e.g. for CJK). This is done via the marked text and the
/// other APIs like selectedRange/firstRectForCharacterRange/etc.
/// 3. Support native dictionary lookup (quickLookWithEvent:) when the user
/// wants to. This mostly involves implementing the attributeSubstring /
/// firstRectForCharacterRange / characterIndexForPoint APIs.
/// There is an inherent difficulty to implementing NSTextInputClient
/// 'correctly', because it assumes we have an entire text storage with
/// indexable ranges. However, we don't have full access to Vim's internal
/// storage, and we are represening the screen view instead in row-major
/// indexing, but this becomes complicated when we want to implement marked
/// texts. We the relevant parts for comments on how we hack around this.
@interface MMCoreTextView : NSView <
NSTextInput
NSTextInputClient
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
, NSFontChanging
, NSMenuItemValidation
Expand Down Expand Up @@ -122,8 +145,21 @@
// NSTextView methods
//
- (void)keyDown:(NSEvent *)event;
- (void)insertText:(id)string;

//
// NSTextInputClient methods
//
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange;
- (void)doCommandBySelector:(SEL)selector;
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange;
- (void)unmarkText;
- (NSRange)selectedRange;
- (NSRange)markedRange;
- (BOOL)hasMarkedText;
- (nullable NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange;
- (nonnull NSArray<NSAttributedStringKey> *)validAttributesForMarkedText;
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(nullable NSRangePointer)actualRange;
- (NSUInteger)characterIndexForPoint:(NSPoint)point;

//
// NSTextContainer methods
Expand Down
Loading