fix(TextEllipsis): fix the logic of calculating the position of ellipsis (#12137)

This commit is contained in:
inottn 2023-07-31 21:34:41 +08:00 committed by GitHub
parent 02b6779c42
commit c95d59e303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ export default defineComponent({
const root = ref<HTMLElement>(); const root = ref<HTMLElement>();
const actionText = computed(() => const actionText = computed(() =>
expanded.value ? props.expandText : props.collapseText, expanded.value ? props.collapseText : props.expandText,
); );
const pxToNum = (value: string | null) => { const pxToNum = (value: string | null) => {
@ -89,7 +89,7 @@ export default defineComponent({
return dots + content.slice(right, end); return dots + content.slice(right, end);
} }
const middle = Math.round((left + right) >> 1); const middle = Math.round((left + right) / 2);
// Set the interception location // Set the interception location
if (position === 'end') { if (position === 'end') {
@ -127,21 +127,20 @@ export default defineComponent({
rightPart[1] - rightPart[0] <= 1 rightPart[1] - rightPart[0] <= 1
) { ) {
return ( return (
content.slice(0, leftPart[1]) + content.slice(0, leftPart[0]) +
dots + dots +
content.slice(rightPart[1], end) content.slice(rightPart[1], end)
); );
} }
const leftMiddle = Math.floor((leftPart[0] + leftPart[1]) >> 1); const leftMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
const rightMiddle = Math.ceil((rightPart[0] + rightPart[1]) >> 1); const rightMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
container.innerText = container.innerText =
props.content.slice(0, leftMiddle) + props.content.slice(0, leftMiddle) +
props.dots + props.dots +
actionText.value + props.content.slice(rightMiddle, end) +
props.dots + props.expandText;
props.content.slice(rightMiddle, end);
if (container.offsetHeight >= maxHeight) { if (container.offsetHeight >= maxHeight) {
return middleTail( return middleTail(