Skip to content

Commit

Permalink
fix layout bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Mar 21, 2024
1 parent af1cee4 commit eba8287
Show file tree
Hide file tree
Showing 21 changed files with 1,249 additions and 1,139 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.down.circle.fill.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.down.circle.svg",
Expand Down
12 changes: 12 additions & 0 deletions Assets.xcassets/Symbols/chevron.down.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "chevron.down.svg",
"idiom" : "universal"
}
]
}
160 changes: 160 additions & 0 deletions Assets.xcassets/Symbols/chevron.down.symbolset/chevron.down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.left.circle.fill.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.left.circle.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.right.circle.fill.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.right.circle.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.up.circle.fill.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "chevron.up.circle.svg",
Expand Down
12 changes: 12 additions & 0 deletions Assets.xcassets/Symbols/chevron.up.symbolset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"symbols" : [
{
"filename" : "chevron.up.svg",
"idiom" : "universal"
}
]
}
160 changes: 160 additions & 0 deletions Assets.xcassets/Symbols/chevron.up.symbolset/chevron.up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "delete.backward.fill.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"author" : "xcode",
"version" : 1
},
"properties" : {
"symbol-rendering-intent" : "template"
},
"symbols" : [
{
"filename" : "delete.backward.svg",
Expand Down
102 changes: 56 additions & 46 deletions SquirrelInputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,12 @@ - (BOOL)processKey:(int)rime_keycode modifiers:(int)rime_modifiers {
if (!panel.locked && !panel.expanded &&
rime_keycode == (is_vertical ? XK_Left : XK_Down)) {
[panel setExpanded:YES];
_currentIndex = NSNotFound;
}
return (BOOL)rime_get_api()->highlight_candidate(_session, newIndex) ||
panel.visible;
} else if (!panel.locked && panel.expanded && panel.activePage == 0 &&
} else if (!panel.locked && panel.expanded && panel.sectionNum == 0 &&
rime_keycode == (is_vertical ? XK_Right : XK_Up)) {
[panel setExpanded:NO];
_currentIndex = NSNotFound;
return panel.visible;
}
}
Expand Down Expand Up @@ -380,8 +378,8 @@ - (void)performAction:(SquirrelAction)action onIndex:(SquirrelIndex)index {
handled = rime_get_api()->select_candidate(_session, index);
break;
case kHIGHLIGHT:
rime_get_api()->highlight_candidate(_session, index);
_currentIndex = index;
handled = rime_get_api()->highlight_candidate(_session, index);
_currentIndex = NSNotFound;
break;
case kDELETE:
handled = rime_get_api()->delete_candidate(_session, index);
Expand Down Expand Up @@ -618,7 +616,7 @@ - (id)composedString:(id)sender {
}

- (NSArray*)candidates:(id)sender {
return _candidates;
return NSApp.squirrelAppDelegate.panel.candidates;
}

- (void)hidePalettes {
Expand Down Expand Up @@ -756,13 +754,12 @@ - (CGRect)getIbeamRect {
- (void)showPanelWithPreedit:(NSString*)preedit
selRange:(NSRange)selRange
caretPos:(NSUInteger)caretPos
candidates:(NSArray<NSString*>*)candidates
comments:(NSArray<NSString*>*)comments
candidateIndices:(NSRange)indexRange
highlightedIndex:(NSUInteger)highlightedIndex
pageNum:(NSUInteger)pageNum
finalPage:(BOOL)finalPage {
finalPage:(BOOL)finalPage
didCompose:(BOOL)didCompose {
// NSLog(@"showPanelWithPreedit:...:");
_candidates = candidates;
SquirrelPanel* panel = NSApp.squirrelAppDelegate.panel;
panel.inputController = self;
panel.IbeamRect = [self getIbeamRect];
Expand All @@ -772,11 +769,11 @@ - (void)showPanelWithPreedit:(NSString*)preedit
[panel showPreedit:preedit
selRange:selRange
caretPos:caretPos
candidates:candidates
comments:comments
candidateIndices:indexRange
highlightedIndex:highlightedIndex
pageNum:pageNum
finalPage:finalPage];
finalPage:finalPage
didCompose:didCompose];
}
}

Expand Down Expand Up @@ -919,36 +916,42 @@ - (void)rimeUpdate {
: (NSUInteger)ctx.menu.highlighted_candidate_index;
BOOL finalPage = (BOOL)ctx.menu.is_last_page;

// update expander and active page status in tabular layout;
// update expander and section status in tabular layout;
// already processed the action if _currentIndex == NSNotFound
if (panel.tabular && !showingStatus) {
if (numCandidates == 0 || didCompose) {
panel.activePage = 0;
panel.sectionNum = 0;
} else if (_currentIndex != NSNotFound) {
NSUInteger currentPageNum = _currentIndex / pageSize;
if (!panel.locked && panel.expanded && panel.topRow && pageNum == 0 &&
highlightedIndex == 0) {
if (!panel.locked && panel.expanded && panel.firstLine &&
pageNum == 0 && highlightedIndex == 0 && _currentIndex == 0) {
panel.expanded = NO;
} else if (!panel.locked && !panel.expanded &&
pageNum > currentPageNum) {
panel.expanded = YES;
}
if (panel.expanded && pageNum > currentPageNum &&
panel.activePage < 4) {
panel.activePage = MIN(panel.activePage + pageNum - currentPageNum,
finalPage ? 4UL : 3UL);
panel.sectionNum < (panel.vertical ? 2 : 4)) {
panel.sectionNum =
MIN(panel.sectionNum + pageNum - currentPageNum,
(finalPage ? 4UL : 3UL) - (panel.vertical ? 2UL : 0UL));
} else if (panel.expanded && pageNum < currentPageNum &&
panel.activePage > 0) {
panel.activePage = MAX(panel.activePage + pageNum - currentPageNum,
panel.sectionNum > 0) {
panel.sectionNum = MAX(panel.sectionNum + pageNum - currentPageNum,
pageNum == 0 ? 0UL : 1UL);
}
}
highlightedIndex += pageSize * panel.activePage;
highlightedIndex += pageSize * panel.sectionNum;
}
_currentIndex =
numCandidates == 0
? NSNotFound
: highlightedIndex + pageSize * (pageNum - panel.activePage);
NSUInteger extraCandidates =
panel.expanded
? (finalPage ? panel.sectionNum : (panel.vertical ? 2 : 4)) *
pageSize
: 0;
NSRange candidateIndices =
NSMakeRange((pageNum - panel.sectionNum) * pageSize,
numCandidates + extraCandidates);
_currentIndex = highlightedIndex + candidateIndices.location;

if (showingStatus) {
[self clearBuffer];
Expand Down Expand Up @@ -1000,53 +1003,60 @@ - (void)rimeUpdate {
caretPos:0];
}
}
if (didCompose || numCandidates == 0) {
[panel.candidates removeAllObjects];
[panel.comments removeAllObjects];
}
// update candidates
NSMutableArray* candidates =
numCandidates ? [[NSMutableArray alloc] init] : nil;
NSMutableArray* comments =
numCandidates ? [[NSMutableArray alloc] init] : nil;
if (numCandidates > 0 && panel.expanded && panel.activePage > 0) {
NSUInteger index = pageSize * (pageNum - panel.activePage);
if (panel.candidates.count < pageSize * pageNum) {
NSUInteger index = panel.candidates.count;
RimeCandidateListIterator iterator;
if (rime_get_api()->candidate_list_from_index(_session, &iterator,
(int)index)) {
NSUInteger endIndex = pageSize * pageNum;
while (index++ < endIndex &&
rime_get_api()->candidate_list_next(&iterator)) {
[candidates addObject:@(iterator.candidate.text)];
[comments addObject:@(iterator.candidate.comment ?: "")];
[panel.candidates addObject:@(iterator.candidate.text)];
[panel.comments addObject:@(iterator.candidate.comment ?: "")];
}
rime_get_api()->candidate_list_end(&iterator);
}
}
for (NSUInteger i = 0; i < numCandidates; ++i) {
[candidates addObject:@(ctx.menu.candidates[i].text)];
[comments addObject:@(ctx.menu.candidates[i].comment ?: "")];
if (panel.candidates.count < pageSize * (pageNum + 1)) {
for (NSUInteger i = 0; i < numCandidates; ++i) {
panel.candidates[pageSize * pageNum + i] =
@(ctx.menu.candidates[i].text);
panel.comments[pageSize * pageNum + i] =
@(ctx.menu.candidates[i].comment ?: "");
}
}
if (numCandidates > 0 && panel.expanded && panel.activePage < 5) {
NSUInteger index = pageSize * (pageNum + 1);
if (panel.candidates.count < NSMaxRange(candidateIndices)) {
NSUInteger index = panel.candidates.count;
RimeCandidateListIterator iterator;
if (rime_get_api()->candidate_list_from_index(_session, &iterator,
(int)index)) {
NSUInteger endIndex = pageSize * (pageNum + 5 - panel.activePage);
NSUInteger endIndex =
pageSize * (pageNum + (panel.vertical ? 3 : 5) - panel.sectionNum);
while (index++ < endIndex &&
rime_get_api()->candidate_list_next(&iterator)) {
[candidates addObject:@(iterator.candidate.text)];
[comments addObject:@(iterator.candidate.comment ?: "")];
[panel.candidates addObject:@(iterator.candidate.text)];
[panel.comments addObject:@(iterator.candidate.comment ?: "")];
}
rime_get_api()->candidate_list_end(&iterator);
candidateIndices.length =
panel.candidates.count - candidateIndices.location;
}
}
[self showPanelWithPreedit:_inlinePreedit && !_showingSwitcherMenu
? nil
: preeditText
selRange:NSMakeRange(start, end - start)
caretPos:_showingSwitcherMenu ? NSNotFound : caretPos
candidates:candidates
comments:comments
candidateIndices:candidateIndices
highlightedIndex:highlightedIndex
pageNum:pageNum
finalPage:finalPage];
finalPage:finalPage
didCompose:didCompose];
rime_get_api()->free_context(&ctx);
} else {
[self hidePalettes];
Expand Down
Loading

0 comments on commit eba8287

Please sign in to comment.