Skip to content

Commit

Permalink
Merge pull request #32 from gnustep/typeselect
Browse files Browse the repository at this point in the history
Type to Select improvements
  • Loading branch information
rmottola authored Jul 15, 2024
2 parents c361b0e + a513e28 commit 6179503
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 85 deletions.
6 changes: 3 additions & 3 deletions FSNode/FSNBrowser.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* FSNBrowser.h
*
* Copyright (C) 2004-2022 Free Software Foundation, Inc.
* Copyright (C) 2004-2024 Free Software Foundation, Inc.
*
* Authors: Enrico Sersale <[email protected]>
* Authors: Enrico Sersale
* Riccardo Mottola <[email protected]>
* Date: July 2004
*
Expand Down Expand Up @@ -69,7 +69,7 @@

NSString *charBuffer;
NSTimeInterval lastKeyPressedTime;
NSInteger alphaNumericalLastColumn;
NSInteger typingBufferColumn;

NSColor *backColor;

Expand Down
54 changes: 31 additions & 23 deletions FSNode/FSNBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ - (id)initWithBaseNode:(FSNode *)bsnode
lastVisibleColumn = visibleColumns - 1;
currentshift = 0;
lastColumnLoaded = -1;
alphaNumericalLastColumn = -1;
typingBufferColumn = -1;

skipUpdateScroller = NO;
lastKeyPressedTime = 0.0;
Expand Down Expand Up @@ -1298,6 +1298,7 @@ - (void)keyDown:(NSEvent *)theEvent
{
NSString *characters = [theEvent characters];
unichar character = 0;
NSString *characterStr = nil;
FSNBrowserColumn *column = [self selectedColumn];
NSMatrix *matrix;

Expand All @@ -1318,6 +1319,7 @@ - (void)keyDown:(NSEvent *)theEvent
if ([characters length] > 0)
{
character = [characters characterAtIndex: 0];
characterStr = [characters substringToIndex: 1];
}

switch (character)
Expand Down Expand Up @@ -1358,6 +1360,11 @@ - (void)keyDown:(NSEvent *)theEvent
[matrix sendDoubleAction];
DESTROY(charBuffer);
return;
case 0x01B: // Escape
DESTROY(charBuffer);
return;
default:
break;
}

if (([characters length] > 0) && (character < 0xF700))
Expand All @@ -1366,46 +1373,47 @@ - (void)keyDown:(NSEvent *)theEvent

if (column)
{
int index = [column index];
NSInteger index = [column index];

matrix = [column cmatrix];

if (matrix == nil)
{
return;
}

if (charBuffer == nil)
{
charBuffer = [characters substringToIndex: 1];
RETAIN (charBuffer);
}
else

if (charBuffer != nil)
{
if (([theEvent timestamp] - lastKeyPressedTime < 500.0)
&& (alphaNumericalLastColumn == index))
if (([theEvent timestamp] - lastKeyPressedTime < 5.0) // seconds
&& (typingBufferColumn == index))
{
NSString *appendBuff = [charBuffer stringByAppendingString:
[characters substringToIndex: 1]];
ASSIGN(charBuffer, appendBuff);
}
else
{
ASSIGN(charBuffer, [characters substringToIndex: 1]);
NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr];

// Try selecting
if ([column selectCellWithPrefix: appendBuffer])
{
ASSIGN(charBuffer, appendBuffer);
[[self window] makeFirstResponder: matrix];
return;
}
// unable to select - fall-through and reinit as if typed is first char
}
}

alphaNumericalLastColumn = index;

ASSIGN(charBuffer, characterStr);
typingBufferColumn = index;
lastKeyPressedTime = [theEvent timestamp];


// Try selecting
if ([column selectCellWithPrefix: charBuffer])
{
[[self window] makeFirstResponder: matrix];
return;
}
}

lastKeyPressedTime = 0.0;
// Selection failed, reinitialize and use mismatching character as new buffer beginning
DESTROY(charBuffer);
}
}

[super keyDown: theEvent];
Expand Down
13 changes: 5 additions & 8 deletions FSNode/FSNBrowserColumn.m
Original file line number Diff line number Diff line change
Expand Up @@ -805,15 +805,12 @@ - (BOOL)selectCellWithPrefix:(NSString *)prefix
NSString *cellStr = nil;
NSInteger i = 0;

// Nothing selected
if (selRow != -1)
cellStr = [[matrix cellAtRow: selRow column: 0] stringValue];
// Nothing selected start from first
if (selRow == -1)
selRow = 0;

if (cellStr && ([cellStr length] > 0) && [cellStr hasPrefix: prefix])
return YES;

// look after current selection
for (i = selRow + 1; i < n; i++)
// look at or after current selection
for (i = selRow; i < n; i++)
{
cellStr = [[matrix cellAtRow: i column: 0] stringValue];

Expand Down
7 changes: 4 additions & 3 deletions FSNode/FSNIconsView.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* FSNIconsView.h
*
* Copyright (C) 2004-2013 Free Software Foundation, Inc.
* Copyright (C) 2004-2024 Free Software Foundation, Inc.
*
* Author: Enrico Sersale <[email protected]>
* Authors: Enrico Sersale
* Riccardo Mottola
* Date: March 2004
*
* This file is part of the GNUstep FSNode framework
Expand Down Expand Up @@ -62,7 +63,7 @@
BOOL forceCopy;

NSString *charBuffer;
NSTimeInterval lastKeyPressed;
NSTimeInterval lastKeyPressedTime;

NSColor *backColor;
NSColor *textColor;
Expand Down
57 changes: 32 additions & 25 deletions FSNode/FSNIconsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ - (id)init
editIcon = nil;

isDragTarget = NO;
lastKeyPressed = 0.;
lastKeyPressedTime = 0.0;
charBuffer = nil;
selectionMask = NSSingleSelectionMask;

Expand Down Expand Up @@ -670,6 +670,7 @@ - (void)keyDown:(NSEvent *)theEvent
{
NSString *characters;
unichar character;
NSString *characterStr = nil;
NSRect vRect, hiddRect;
NSPoint p;
float x, y, w, h;
Expand All @@ -678,9 +679,13 @@ - (void)keyDown:(NSEvent *)theEvent
character = 0;

if ([characters length] > 0)
character = [characters characterAtIndex: 0];
{
character = [characters characterAtIndex: 0];
characterStr = [characters substringToIndex: 1];
}

switch (character) {
switch (character)
{
case NSPageUpFunctionKey:
vRect = [self visibleRect];
p = vRect.origin;
Expand Down Expand Up @@ -745,40 +750,42 @@ - (void)keyDown:(NSEvent *)theEvent
[self openSelectionInNewViewer: closesndr];
return;
}

case 0x01B: // Escape
DESTROY(charBuffer);
return;
default:
break;
}

if (([characters length] > 0) && (character < 0xF700))
{
SEL icnwpSel = @selector(selectIconWithPrefix:);
IMP icnwp = [self methodForSelector: icnwpSel];

if (charBuffer == nil) {
charBuffer = [characters substringToIndex: 1];
RETAIN (charBuffer);
lastKeyPressed = 0.0;
}
else
if (charBuffer != nil)
{
if ([theEvent timestamp] - lastKeyPressed < 500.0)
{
ASSIGN (charBuffer, ([charBuffer stringByAppendingString:
[characters substringToIndex: 1]]));
}
else
if ([theEvent timestamp] - lastKeyPressedTime < 5.0)
{
ASSIGN (charBuffer, ([characters substringToIndex: 1]));
lastKeyPressed = 0.0;
NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr];

// Try selecting
if ([self selectIconWithPrefix: appendBuffer])
{
ASSIGN(charBuffer, appendBuffer);
return;
}
// unable to select - fall-through and reinit as if typed is first char
}
}

lastKeyPressed = [theEvent timestamp];
ASSIGN(charBuffer, characterStr);
lastKeyPressedTime = [theEvent timestamp];

if ((*icnwp)(self, icnwpSel, charBuffer)) {
return;
}
// Try selecting
if ([self selectIconWithPrefix: charBuffer])
{
return;
}

// Selection failed, reinitialize and use mismatching character as new buffer beginning
DESTROY(charBuffer);
}

[super keyDown: theEvent];
Expand Down
2 changes: 1 addition & 1 deletion FSNode/FSNListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
{
id dsource;
NSString *charBuffer;
NSTimeInterval lastKeyPressed;
NSTimeInterval lastKeyPressedTime;

NSTimer *clickTimer;
}
Expand Down
47 changes: 25 additions & 22 deletions FSNode/FSNListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ - (id)initWithFrame:(NSRect)frameRect
[self setTarget: dsource];
[self setDoubleAction: @selector(doubleClickOnListView:)];

lastKeyPressed = 0.;
lastKeyPressedTime = 0.0;
charBuffer = nil;

[self registerForDraggedTypes: [NSArray arrayWithObjects:
Expand Down Expand Up @@ -2762,13 +2762,15 @@ - (void)keyDown:(NSEvent *)theEvent
{
NSString *characters = [theEvent characters];
unichar character = 0;
NSString *characterStr = nil;
NSRect vRect, hiddRect;
NSPoint p;
float x, y, w, h;

if ([characters length] > 0)
{
character = [characters characterAtIndex: 0];
characterStr = [characters substringToIndex: 1];
}

switch (character)
Expand Down Expand Up @@ -2813,44 +2815,45 @@ - (void)keyDown:(NSEvent *)theEvent
BOOL closesndr = ((flags == NSAlternateKeyMask)
|| (flags == NSControlKeyMask));
[dsource openSelectionInNewViewer: closesndr];
DESTROY(charBuffer);
return;
}

case 0x01B: // Escape
DESTROY(charBuffer);
return;
default:
break;
}

if (([characters length] > 0) && (character < 0xF700))
{
SEL icnwpSel = @selector(selectRepWithPrefix:);
IMP icnwp = [dsource methodForSelector: icnwpSel];

if (charBuffer == nil)
if (charBuffer != nil)
{
charBuffer = [characters substringToIndex: 1];
RETAIN (charBuffer);
lastKeyPressed = 0.0;
}
else
{
if ([theEvent timestamp] - lastKeyPressed < 500.0)
if ([theEvent timestamp] - lastKeyPressedTime < 5.0) // seconds
{
ASSIGN (charBuffer, ([charBuffer stringByAppendingString:
[characters substringToIndex: 1]]));
}
else
{
ASSIGN (charBuffer, ([characters substringToIndex: 1]));
lastKeyPressed = 0.0;
NSString *appendBuffer = [charBuffer stringByAppendingString:characterStr];

// Try selecting
if ([dsource selectRepWithPrefix:appendBuffer])
{
ASSIGN(charBuffer, appendBuffer);
return;
}
// unable to select - fall-through and reinit as if typed is first char
}
}

lastKeyPressed = [theEvent timestamp];
ASSIGN(charBuffer, characterStr);
lastKeyPressedTime = [theEvent timestamp];

if ((*icnwp)(dsource, icnwpSel, charBuffer))
// Try selecting
if ([dsource selectRepWithPrefix:charBuffer])
{
return;
}

// Selection failed, reinitialize and use mismatching character as new buffer beginning
DESTROY(charBuffer);
}

[super keyDown: theEvent];
Expand Down

0 comments on commit 6179503

Please sign in to comment.