}
};
- 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 (
- <LocationIndex key={`marker-${index}`} onClick={onClick} selected={message != null}>
+ <LocationIndex
+ key={`marker-${index}`}
+ leading={leading}
+ onClick={onClick}
+ selected={message != null}>
<span href="#" ref={ref}>
{index + 1}
</span>
});
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 => {
highlightedLocationMessage != null && highlightedLocationMessage.index === marker
? highlightedLocationMessage.text
: null;
- renderedTokens.push(this.renderMarker(marker, message));
+ renderedTokens.push(this.renderMarker(marker, message, leadingMarker));
});
}
renderedTokens.push(
{token.text}
</span>
);
+
+ // keep leadingMarker truthy if previous token has only whitespaces
+ leadingMarker = (index === 0 ? true : leadingMarker) && !token.text.trim().length;
});
return (
/*::
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 (
- <div className={classNames('location-index', { selected })} {...clickAttributes} {...other}>
+ <div
+ className={classNames('location-index', { 'is-leading': leading, selected })}
+ {...clickAttributes}
+ {...other}>
{children}
</div>
);