-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: #1772 code review 组件,代码展开按钮与评论相邻时,点击展开按钮会报错 #1773
Open
luoyimaid
wants to merge
1
commit into
DevCloudFE:dev
Choose a base branch
from
luoyimaid:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,7 @@ export function parseDiffCode(container: HTMLElement, code: string, outputFormat | |
const trList = diffHtmlStr.match(TableTrReg) as RegExpMatchArray; | ||
const trListLength = trList.length; | ||
let newTrStr = ''; | ||
const offset = trListLength / 2; | ||
const offset = Math.floor(trListLength / 2); | ||
for (let i = 0; i < trListLength / 2; i++) { | ||
const leftTdList = trList[i].match(TableTdReg); | ||
const rightTdList = trList[i + offset].match(TableTdReg); | ||
|
@@ -197,10 +197,37 @@ export function setLineNumberInDataset(trNode: HTMLElement, prevL: number, prevR | |
|
||
// 中间行展开后,折叠行数小于阈值时,将向上向下展开按钮更新为全部展开 | ||
export function updateExpandUpDownButton(trNode: HTMLElement) { | ||
trNode.children[0].children[0].remove(); | ||
trNode.children[0].children[0].classList.remove('up-expand'); | ||
trNode.children[0].children[0].classList.add('all-expand'); | ||
trNode.children[0].children[0].innerHTML = AllExpandIcon(); | ||
trNode.children[0]?.children[0]?.remove(); | ||
trNode.children[0]?.children[0]?.classList.remove('up-expand'); | ||
trNode.children[0]?.children[0]?.classList.add('all-expand'); | ||
trNode.children[0]?.children[0] && (trNode.children[0].children[0].innerHTML = AllExpandIcon()); | ||
} | ||
|
||
/** | ||
* 查找给定节点的前一个同级元素节点。 | ||
* 适用于下一行是新增行或者删除行的情况 | ||
* | ||
* @param _node 如果折叠行后一行左边获取不到行数,则寻找第一个左边有行数的行。 | ||
* @returns 返回找到的后一个同级元素节点,如果没有找到则返回null。 | ||
*/ | ||
export function findNextElement(_node: Element): Element { | ||
if (_node.children[0]?.innerText) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处以及下文代码一些地方会存在TS错误 |
||
return _node; | ||
} | ||
return findNextElement(_node.nextElementSibling); | ||
} | ||
/** | ||
* 查找给定节点的前一个同级元素节点。 | ||
* 适用于上一行是新增行或者删除行或者评论行的情况 | ||
* | ||
* @param _node 如果折叠行后一行左边获取不到行数,则寻找第一个左边有行数的行。 | ||
* @returns 返回找到的前一个同级元素节点,如果没有找到则返回null。 | ||
*/ | ||
export function findPrevElement(_node: Element): Element { | ||
if (_node.children[0]?.innerText) { | ||
return _node; | ||
} | ||
return findPrevElement(_node.previousElementSibling); | ||
} | ||
|
||
/* | ||
|
@@ -221,20 +248,20 @@ export function updateLineNumberInDatasetForDoubleColumn( | |
let nextR: number; | ||
let prevR: number; | ||
if (position === 'top') { | ||
const nextLineNode = trNode.nextElementSibling as HTMLElement; | ||
const nextLineNode = findNextElement(trNode.nextElementSibling) as HTMLElement; | ||
nextL = parseInt((nextLineNode.children[0] as HTMLElement).innerText) - 1; | ||
prevL = Math.max(nextL - expandThreshold + 1, 1); | ||
nextR = parseInt((nextLineNode.children[2] as HTMLElement).innerText) - 1; | ||
prevR = Math.max(nextR - expandThreshold + 1, 1); | ||
} else if (position === 'bottom') { | ||
const prevLineNode = trNode.previousElementSibling as HTMLElement; | ||
const prevLineNode = findPrevElement(trNode.previousElementSibling) as HTMLElement; | ||
prevL = parseInt((prevLineNode?.children[0] as HTMLElement)?.innerText) + 1; | ||
nextL = prevL + expandThreshold - 1; | ||
prevR = parseInt((prevLineNode?.children[2] as HTMLElement)?.innerText) + 1; | ||
nextR = prevR + expandThreshold - 1; | ||
} else { | ||
const prevLineNode = trNode.previousElementSibling as HTMLElement; | ||
const nextLineNode = trNode.nextElementSibling as HTMLElement; | ||
const prevLineNode = findPrevElement(trNode.previousElementSibling) as HTMLElement; | ||
const nextLineNode = findNextElement(trNode.nextElementSibling) as HTMLElement; | ||
const prevLineNumber = parseInt((prevLineNode.children[0] as HTMLElement).innerText); | ||
const nextLineNumber = parseInt((nextLineNode.children[0] as HTMLElement).innerText); | ||
prevL = prevLineNumber + 1; | ||
|
@@ -243,6 +270,7 @@ export function updateLineNumberInDatasetForDoubleColumn( | |
nextR = parseInt((nextLineNode.children[2] as HTMLElement).innerText) - 1; | ||
const isExpandAll = nextLineNumber - prevLineNumber <= expandThreshold; | ||
if (isExpandAll && updateExpandButton) { | ||
trNode.style.display = 'none'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处的display置为none操作是用来何种作用呢 |
||
updateExpandUpDownButton(trNode); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在单栏模式也存在此问题,针对该问题修复可以尝试两种模式考虑