use of com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo in project gerrit by GerritCodeReview.
the class UnifiedCommentManager method newDraftOnGutterClick.
@Override
void newDraftOnGutterClick(CodeMirror cm, String gutterClass, int cmLinePlusOne) {
if (!Gerrit.isSignedIn()) {
signInCallback(cm).run();
} else {
LineRegionInfo info = ((Unified) host).getLineRegionInfoFromCmLine(cmLinePlusOne - 1);
DisplaySide side = gutterClass.equals(UnifiedTable.style.lineNumbersLeft()) ? DisplaySide.A : DisplaySide.B;
int line = info.line;
if (info.getSide() != side) {
line = host.lineOnOther(info.getSide(), line).getLine();
}
insertNewDraft(side, line + 1);
}
}
use of com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo in project gerrit by GerritCodeReview.
the class UnifiedCommentManager method newDraft.
@Override
void newDraft(CodeMirror cm) {
if (cm.somethingSelected()) {
FromTo fromTo = adjustSelection(cm);
Pos from = fromTo.from();
Pos to = fromTo.to();
Unified unified = (Unified) host;
UnifiedChunkManager manager = unified.getChunkManager();
LineRegionInfo fromInfo = unified.getLineRegionInfoFromCmLine(from.line());
LineRegionInfo toInfo = unified.getLineRegionInfoFromCmLine(to.line());
DisplaySide side = toInfo.getSide();
// start line to be on the same side as the end line.
if ((fromInfo.type == RegionType.INSERT || fromInfo.type == RegionType.COMMON) && toInfo.type == RegionType.DELETE) {
LineOnOtherInfo infoOnSideA = manager.lineMapper.lineOnOther(DisplaySide.B, fromInfo.line);
int startLineOnSideA = infoOnSideA.getLine();
if (infoOnSideA.isAligned()) {
from.line(startLineOnSideA);
} else {
from.line(startLineOnSideA + 1);
}
from.ch(0);
to.line(toInfo.line);
} else if (fromInfo.type == RegionType.DELETE && toInfo.type == RegionType.INSERT) {
LineOnOtherInfo infoOnSideB = manager.lineMapper.lineOnOther(DisplaySide.A, fromInfo.line);
int startLineOnSideB = infoOnSideB.getLine();
if (infoOnSideB.isAligned()) {
from.line(startLineOnSideB);
} else {
from.line(startLineOnSideB + 1);
}
from.ch(0);
to.line(toInfo.line);
} else if (fromInfo.type == RegionType.DELETE && toInfo.type == RegionType.COMMON) {
int toLineOnSideA = manager.lineMapper.lineOnOther(DisplaySide.B, toInfo.line).getLine();
from.line(fromInfo.line);
// Force the end line to be on the same side as the start line.
to.line(toLineOnSideA);
side = DisplaySide.A;
} else {
// Common case
from.line(fromInfo.line);
to.line(toInfo.line);
}
addDraftBox(side, CommentInfo.create(getPath(), getStoredSideFromDisplaySide(side), to.line() + 1, CommentRange.create(fromTo), false)).setEdit(true);
cm.setCursor(Pos.create(host.getCmLine(to.line(), side), to.ch()));
cm.setSelection(cm.getCursor());
} else {
int cmLine = cm.getLineNumber(cm.extras().activeLine());
LineRegionInfo info = ((Unified) host).getLineRegionInfoFromCmLine(cmLine);
insertNewDraft(info.getSide(), cmLine + 1);
}
}
use of com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo in project gerrit by GerritCodeReview.
the class UnifiedCommentManager method getCommentGroupOnActiveLine.
@Override
CommentGroup getCommentGroupOnActiveLine(CodeMirror cm) {
CommentGroup group = null;
if (cm.extras().hasActiveLine()) {
int cmLinePlusOne = cm.getLineNumber(cm.extras().activeLine()) + 1;
LineRegionInfo info = ((Unified) host).getLineRegionInfoFromCmLine(cmLinePlusOne - 1);
CommentGroup forSide = map(info.getSide()).get(cmLinePlusOne);
group = forSide == null ? map(info.getSide().otherSide()).get(cmLinePlusOne) : forSide;
}
return group;
}
use of com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo in project gerrit by GerritCodeReview.
the class UnifiedCommentManager method getTokenSuffixForActiveLine.
@Override
String getTokenSuffixForActiveLine(CodeMirror cm) {
int cmLinePlusOne = cm.getLineNumber(cm.extras().activeLine()) + 1;
LineRegionInfo info = ((Unified) host).getLineRegionInfoFromCmLine(cmLinePlusOne - 1);
return (info.getSide() == DisplaySide.A ? "a" : "") + cmLinePlusOne;
}
Aggregations