From 0b9d353145660ea802d50f2c3e177976ac26724c Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 10 Oct 2017 10:24:09 +0200 Subject: SONAR-9690 Improve positioning of secondary locations markers --- .../js/components/SourceViewer/components/LineCode.js | 18 +++++++++++++++--- .../src/main/js/components/common/LocationIndex.css | 6 ++++++ .../src/main/js/components/common/LocationIndex.js | 8 ++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js index ad71197cf9c..4cedfd753c4 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCode.js @@ -136,12 +136,16 @@ export default class LineCode extends React.PureComponent { } }; - renderMarker(index /*: number */, message /*: ?string */) { + renderMarker(index /*: number */, message /*: ?string */, leading /*: boolean */ = false) { const { onLocationSelect } = this.props; const onClick = onLocationSelect ? () => onLocationSelect(index) : undefined; const ref = message != null ? node => (this.activeMarkerNode = node) : undefined; return ( - + {index + 1} @@ -193,6 +197,11 @@ export default class LineCode extends React.PureComponent { }); const renderedTokens = []; + + // track if the first marker is displayed before the source code + // set `false` for the first token in a row + let leadingMarker = false; + tokens.forEach((token, index) => { if (token.markers.length > 0) { token.markers.forEach(marker => { @@ -200,7 +209,7 @@ export default class LineCode extends React.PureComponent { highlightedLocationMessage != null && highlightedLocationMessage.index === marker ? highlightedLocationMessage.text : null; - renderedTokens.push(this.renderMarker(marker, message)); + renderedTokens.push(this.renderMarker(marker, message, leadingMarker)); }); } renderedTokens.push( @@ -208,6 +217,9 @@ export default class LineCode extends React.PureComponent { {token.text} ); + + // keep leadingMarker truthy if previous token has only whitespaces + leadingMarker = (index === 0 ? true : leadingMarker) && !token.text.trim().length; }); return ( diff --git a/server/sonar-web/src/main/js/components/common/LocationIndex.css b/server/sonar-web/src/main/js/components/common/LocationIndex.css index 73b5cd8986e..a1da0ffdefd 100644 --- a/server/sonar-web/src/main/js/components/common/LocationIndex.css +++ b/server/sonar-web/src/main/js/components/common/LocationIndex.css @@ -21,6 +21,12 @@ background-color: #ccc; } +.location-index.is-leading { + position: absolute; + margin: 1px 0 0 -4px !important; + transform: translateX(-100%); +} + .location-index[tabindex] { cursor: pointer; } diff --git a/server/sonar-web/src/main/js/components/common/LocationIndex.js b/server/sonar-web/src/main/js/components/common/LocationIndex.js index 2effb6e44ca..43ddc0de0bf 100644 --- a/server/sonar-web/src/main/js/components/common/LocationIndex.js +++ b/server/sonar-web/src/main/js/components/common/LocationIndex.js @@ -25,18 +25,22 @@ import './LocationIndex.css'; /*:: type Props = { children?: React.Element<*>, + leading?: boolean, onClick?: () => void, selected?: boolean }; */ export default function LocationIndex(props /*: Props */) { - const { children, onClick, selected, ...other } = props; + const { children, leading, onClick, selected, ...other } = props; const clickAttributes = onClick ? { onClick, role: 'button', tabIndex: 0 } : {}; // put {...others} because Tooltip sets some event handlers return ( -
+
{children}
); -- cgit v1.2.3