@@ -29,7 +29,7 @@ function applySgrFragments(activeStyles, fragments) {
2929}
3030
3131function undoAnsiCodes ( activeStyles ) {
32- return [ ...activeStyles . keys ( ) ] . reverse ( ) . join ( '' ) ;
32+ return [ ...activeStyles . keys ( ) ] . toReversed ( ) . join ( '' ) ;
3333}
3434
3535function closeHyperlink ( hyperlinkToken ) {
@@ -63,13 +63,21 @@ function hasSgrStartFragment(token) {
6363 return token . fragments . some ( fragment => fragment . type === 'start' ) ;
6464}
6565
66- function clearPendingHyperlink ( parameters ) {
66+ function discardPendingHyperlink ( parameters ) {
6767 if (
6868 parameters . activeHyperlink
6969 && ! parameters . activeHyperlinkHasVisibleText
7070 && parameters . activeHyperlinkOutputIndex !== undefined
7171 ) {
72- parameters . returnValue = parameters . returnValue . slice ( 0 , parameters . activeHyperlinkOutputIndex ) ;
72+ const openCodeLength = parameters . activeHyperlink . code . length ;
73+ parameters . returnValue = parameters . returnValue . slice ( 0 , parameters . activeHyperlinkOutputIndex ) + parameters . returnValue . slice ( parameters . activeHyperlinkOutputIndex + openCodeLength ) ;
74+
75+ if (
76+ parameters . pendingSgrOutputIndex !== undefined
77+ && parameters . pendingSgrOutputIndex > parameters . activeHyperlinkOutputIndex
78+ ) {
79+ parameters . pendingSgrOutputIndex -= openCodeLength ;
80+ }
7381 }
7482
7583 parameters . activeHyperlink = undefined ;
@@ -126,7 +134,7 @@ function applyHyperlinkToken(parameters) {
126134 && parameters . activeHyperlink
127135 && ! parameters . activeHyperlinkHasVisibleText
128136 ) {
129- clearPendingHyperlink ( parameters ) ;
137+ discardPendingHyperlink ( parameters ) ;
130138 return parameters ;
131139 }
132140
@@ -255,13 +263,15 @@ export default function sliceAnsi(string, start, end) {
255263 activeHyperlink,
256264 activeHyperlinkHasVisibleText,
257265 activeHyperlinkOutputIndex,
266+ pendingSgrOutputIndex,
258267 returnValue,
259268 } ;
260- clearPendingHyperlink ( hyperlinkState ) ;
269+ discardPendingHyperlink ( hyperlinkState ) ;
261270 ( {
262271 activeHyperlink,
263272 activeHyperlinkHasVisibleText,
264273 activeHyperlinkOutputIndex,
274+ pendingSgrOutputIndex,
265275 returnValue,
266276 } = hyperlinkState ) ;
267277 }
0 commit comments