Skip to content
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

Add code range highlighting and stepping #843

Merged
merged 1 commit into from
Feb 25, 2020

Conversation

treyhoover
Copy link
Contributor

@treyhoover treyhoover commented Feb 17, 2020

Description

This adds code range highlighting/stepper support, similar to this project.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Added tests for the searchChildrenForStepper util, which is handling most of the logic.

@treyhoover treyhoover force-pushed the feature/code-stepping branch 4 times, most recently from 7fcfe79 to deeaa92 Compare February 21, 2020 15:39
@treyhoover treyhoover changed the title [WIP] Add code range highlighting and stepping Add code range highlighting and stepping Feb 21, 2020
examples/one-page.html Outdated Show resolved Hide resolved
@ryan-roemer
Copy link
Member

Weirdly, when I run yarn build-one-page, I get a diff:

diff --git a/examples/one-page.html b/examples/one-page.html
index b7ea1a8..f657c7d 100644
--- a/examples/one-page.html
+++ b/examples/one-page.html
@@ -64,8 +64,7 @@
       `;
       // SPECTACLE_CLI_TEMPLATE_END
 
-      const formidableLogo =
-        'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';
+      const formidableLogo = 'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';
       const cppCodeBlock = `#include <iostream>
       #include <cstdlib>
       #include <sstream>
@@ -132,22 +131,13 @@
           </${Slide}>
           <${Slide} transitionEffect="slide">
             <${Heading}>Code Blocks</${Heading}>
-            <${Stepper} defaultValue=${[]} values=${[
-        [1, 1],
-        [23, 25],
-        [40, 42]
-      ]}>
+            <${Stepper} defaultValue=${[]} values=${[[1, 1], [23, 25], [40, 42]]}>
               ${(value, step) => html`<${Box} position="relative">
-                <${CodePane} highlightStart=${value[0]} highlightEnd=${
-                value[1]
-              } fontSize=${18} language="cpp" autoFillHeight>
+                <${CodePane} highlightStart=${value[0]} highlightEnd=${value[1]} fontSize=${18} language="cpp" autoFillHeight>
                   ${cppCodeBlock}
                 </${CodePane}>
                 <${Box} position="absolute" bottom="0rem" left="0rem" right="0rem" bg="black">
-                  ${step === 1 &&
-                    html`<${Text} fontSize="1.5rem" margin="0rem">This is a note!</${Text}>`}${step ===
-                2 &&
-                html`<${Text} fontSize="1.5rem" margin="0rem">You can use the stepper state to render whatever you like as you step through the code.</${Text}>`}
+                  ${step === 1 && html`<${Text} fontSize="1.5rem" margin="0rem">This is a note!</${Text}>`}${step === 2 && html`<${Text} fontSize="1.5rem" margin="0rem">You can use the stepper state to render whatever you like as you step through the code.</${Text}>`}
                 </${Box}>
               </${Box}>`}
             </${Stepper}>
@@ -183,16 +173,9 @@
               </${Box}>
             </${Grid}>
             <${Grid} gridTemplateColumns="1fr 1fr 1fr" gridTemplateRows="1fr 1fr 1fr" alignItems="center" justifyContent="center" gridRowGap=${1}>
-              ${Array(9)
-                .fill('')
-                .map(
-                  (
-                    _,
-                    index
-                  ) => html`<${FlexBox} paddingTop=${0} key=${`formidable-logo-${index}`} flex=${1}>
+              ${Array(9).fill('').map((_, index) => html`<${FlexBox} paddingTop=${0} key=${`formidable-logo-${index}`} flex=${1}>
                 <${Image} src=${formidableLogo} width=${100} />
-              </${FlexBox}>`
-                )}
+              </${FlexBox}>`)}
             </${Grid}>
           </${Slide}>
           <${Slide}>
@@ -242,12 +225,7 @@
         </${Deck}>
       `;
 
-      ReactDOM.render(
-        html`
-          <${Presentation} />
-        `,
-        document.getElementById('root')
-      );
+      ReactDOM.render(html`<${Presentation}/>`, document.getElementById('root'));
     </script>
   </body>
 </html>

@treyhoover can you run yarn build-one-page again and see if you get a diff?

@treyhoover treyhoover force-pushed the feature/code-stepping branch from deeaa92 to 5a750ab Compare February 21, 2020 18:04
@treyhoover
Copy link
Contributor Author

@ryan-roemer Weird indeed. Yes, I got one when I ran it again. Updated now.

Copy link
Member

@ryan-roemer ryan-roemer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work!

As I'm less familiar with the core React code workings, let's get another 👍 approval for that.

@treyhoover
Copy link
Contributor Author

Should I merge now, @carlos-kelly ?

theme: propTypes.object
};

CodePane.defaultProps = {
language: 'javascript',
theme: theme,
fontSize: 15
fontSize: 15,
highlightStart: -Infinity,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this value needs to be set and we can't rely on null?

@treyhoover
Copy link
Contributor Author

treyhoover commented Feb 21, 2020 via email

@treyhoover treyhoover force-pushed the feature/code-stepping branch 3 times, most recently from 09108c7 to bd35a5a Compare February 25, 2020 22:02
@treyhoover treyhoover force-pushed the feature/code-stepping branch from bd35a5a to 6000566 Compare February 25, 2020 22:07
@treyhoover treyhoover merged commit aea2ec0 into task/rewrite Feb 25, 2020
@treyhoover treyhoover deleted the feature/code-stepping branch February 25, 2020 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants