angular - 文字在 word 内被破坏
问题描述
在我的自定义组件中,我遇到了 CSS 问题。虽然我已经在组件上设置了类ion-text-wrap
,但它打破了一些单词。
这是我的组件模板
<div class="ion-text-wrap history_main"
[style.width.px]="width" [style.height.px]="height"
>
<span *ngFor="let singleElement of elements" class="moveEntry">{{singleElement.text}}</span>
</div>
这是我的组件样式
.history_main {
overflow: scroll;
background-color: beige;
word-wrap: break-word;
word-break: break-word;
}
.moveEntry {
font-size: larger;
margin: 0 10px;
}
这是隐藏的代码
import { Component, OnInit, Input, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'loloof64-chesshistory',
templateUrl: './loloof64-chesshistory.component.html',
styleUrls: ['./loloof64-chesshistory.component.scss'],
})
export class Loloof64ChesshistoryComponent implements OnInit {
@Input() height = 200.0;
@Input() width = 200.0;
elements = [];
constructor(private changeDetector: ChangeDetectorRef,) { }
ngOnInit() {}
addMoveFan = (moveFan) => {
this.elements.push({
text: moveFan,
});
this.changeDetector.detectChanges();
}
clear = () => {
this.elements = [];
}
}
以及问题的截图:
在这里,您可以在第一行末尾的“Kd3”上进行奇怪的中断。
据我说,这与使用 Unicode 字符有关,但即使有这样的假设,我也无法找到解决方案。
这是我从 SAN 到 FAN 的转换功能
convertSanToFan({moveSan, whiteTurn}) {
moveSan = moveSan.replace(/K/g, whiteTurn ? '\u2654' : '\u265A');
moveSan = moveSan.replace(/Q/g, whiteTurn ? '\u2655' : '\u265B');
moveSan = moveSan.replace(/R/g, whiteTurn ? '\u2656' : '\u265C');
moveSan = moveSan.replace(/B/g, whiteTurn ? '\u2657' : '\u265D');
moveSan = moveSan.replace(/N/g, whiteTurn ? '\u2658' : '\u265E');
return moveSan;
}
也许可以改进 Unicode 的使用,以便将字符串视为一个完整的单词?
另请注意, ion-text-nowrap 类不适用,因为它将所有元素保持在同一行。
还尝试调用.normalize()
生成的字符串。
解决方案
编辑:我最终使用了 flexbox 系统,解决了这个问题
.history_main {
display: flex;
flex-wrap: wrap;
overflow: scroll;
background-color: beige;
}
编辑:事实上,这并不能解决问题。
事实上,问题在于 move san 到 move fan 转换方法。每次转换后我都需要调用 normalize("NFD") 。
convertSanToFan({moveSan, whiteTurn}) {
moveSan = moveSan.replace(/K/g, whiteTurn ? '\u2654' : '\u265A').normalize("NFD");
moveSan = moveSan.replace(/Q/g, whiteTurn ? '\u2655' : '\u265B').normalize("NFD");
moveSan = moveSan.replace(/R/g, whiteTurn ? '\u2656' : '\u265C').normalize("NFD");
moveSan = moveSan.replace(/B/g, whiteTurn ? '\u2657' : '\u265D').normalize("NFD");
moveSan = moveSan.replace(/N/g, whiteTurn ? '\u2658' : '\u265E').normalize("NFD");
return moveSan;
}
感谢评论中的@Ashokan 建议。
为什么选择 NFD?不知道为什么会这样,只是觉得是对的。
推荐阅读
- python - Django 2.1.7 中的子进程
- reactjs - 在 axios 请求后自行更新状态?
- powershell - 删除所有包含重复单词的行
- android - 无法找到在 Firebase 测试实验室上运行的 Espresso 脚本中检测不同设备的相机按钮的解决方案
- python - 为什么不能在 python 多处理中腌制方法?
- powershell - 结合Powershell脚本调用函数并获取AD属性值
- openapi - 使用 dredd 验证 OpenAPI 响应
- html - VoiceOver 朗读隐藏元素
- javascript - 如何编译和评估对象上指定的逻辑运算符和操作数?
- javascript - 这个 filterSystem 函数有什么问题