cc-pets 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ## [Unreleased]
6
6
 
7
7
  ## [1.3.2] - 2026-08-17
8
- - 优化“切换桌宠”子菜单:素材名称最多显示 4 个完整字符,超出后追加 `...`;外部素材增加
8
+ - 优化“切换桌宠”子菜单:素材名称按 5 个中文字符的视觉宽度展示,超出后追加 `...`;外部素材增加
9
9
  垃圾桶删除入口,首次点击后原位置变为红字“确认”,再次点击才执行删除。切换或删除素材时
10
10
  子菜单保持展开,并立即更新当前项勾选和删除状态;内置素材及当前已应用素材不显示删除图标。
11
11
 
@@ -10,7 +10,7 @@ static const CGFloat PetDragThreshold = 3.0;
10
10
  static const CGFloat PetMenuRowWidth = 194.0;
11
11
  static const CGFloat PetSubmenuRowWidth = 134.0;
12
12
  // 与“系统通知”里文案到开关的间距共用,素材名称到删除按钮也保持一致。
13
- static const CGFloat PetMenuControlGap = 6.0;
13
+ static const CGFloat PetMenuControlGap = 8.0;
14
14
  static const NSInteger PetMenuCheckViewTag = 1001;
15
15
  static const NSInteger PetMenuDeleteButtonTag = 1002;
16
16
 
@@ -441,34 +441,34 @@ static const NSInteger PetMenuDeleteButtonTag = 1002;
441
441
  }
442
442
  }
443
443
  }
444
- - (NSString *)displayNameForPetName:(NSString *)name {
444
+ - (NSString *)displayNameForPetName:(NSString *)name font:(NSFont *)font maxWidth:(CGFloat)maxWidth {
445
445
  if (![name isKindOfClass:NSString.class]) return @"";
446
- __block NSUInteger count = 0;
447
- __block NSUInteger end = 0;
448
- __block BOOL truncated = NO;
446
+ NSDictionary<NSAttributedStringKey, id> *attributes = @{NSFontAttributeName: font};
447
+ if ([name sizeWithAttributes:attributes].width <= maxWidth) return name;
448
+
449
+ NSString *suffix = @"...";
450
+ NSMutableString *prefix = [NSMutableString string];
449
451
  [name enumerateSubstringsInRange:NSMakeRange(0, name.length)
450
452
  options:NSStringEnumerationByComposedCharacterSequences
451
453
  usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
452
- if (count == 4) {
453
- truncated = YES;
454
+ NSString *candidate = [NSString stringWithFormat:@"%@%@%@", prefix, substring, suffix];
455
+ if ([candidate sizeWithAttributes:attributes].width > maxWidth) {
454
456
  *stop = YES;
455
457
  return;
456
458
  }
457
- count += 1;
458
- end = NSMaxRange(substringRange);
459
+ [prefix appendString:substring];
459
460
  }];
460
- if (!truncated) return name;
461
- return [[name substringToIndex:end] stringByAppendingString:@"..."];
461
+ return [prefix stringByAppendingString:suffix];
462
462
  }
463
463
  - (NSMenuItem *)addPetOption:(NSDictionary *)pet toMenu:(NSMenu *)menu {
464
464
  NSString *petID = [pet[@"id"] isKindOfClass:NSString.class] ? pet[@"id"] : @"";
465
465
  NSString *name = [pet[@"name"] isKindOfClass:NSString.class] ? pet[@"name"] : @"";
466
- NSString *displayName = [self displayNameForPetName:name];
467
466
  BOOL selected = [petID isEqualToString:self.currentPetID];
468
467
  BOOL deletable = [petID hasPrefix:@"external:"];
469
468
 
470
469
  NSFont *font = [NSFont menuFontOfSize:13];
471
- CGFloat nameWidth = ceil([@"桌宠素材..." sizeWithAttributes:@{NSFontAttributeName: font}].width);
470
+ CGFloat nameWidth = ceil([@"桌宠素材名..." sizeWithAttributes:@{NSFontAttributeName: font}].width);
471
+ NSString *displayName = [self displayNameForPetName:name font:font maxWidth:nameWidth];
472
472
  const CGFloat checkWidth = 14;
473
473
  const CGFloat leadingInset = 6;
474
474
  const CGFloat nameX = leadingInset + checkWidth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": "wangxinyusqn",
6
6
  "license": "MIT",