Skip to content

Commit 48d2182

Browse files
committed
Fix line number width
- set `line-number` width based on total number of lines - set target in `webpack` config as `electron`
1 parent fdda524 commit 48d2182

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ npm-debug.log*
44
*.lock
55
package-lock.json
66
.DS_Store
7-
.vs-code
7+
.vs-code
8+
tags

dist/bundle.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21459,6 +21459,11 @@ var CodeView = function (_Component) {
2145921459
}, 750);
2146021460
} catch (e) {}
2146121461
}
21462+
}, {
21463+
key: 'spaceFixedLineNumber',
21464+
value: function spaceFixedLineNumber(curLine, totLines) {
21465+
return '\xA0'.repeat(totLines.toString().length - curLine.toString().length) + curLine.toString();
21466+
}
2146221467
}, {
2146321468
key: 'componentDidMount',
2146421469
value: function componentDidMount() {
@@ -21520,7 +21525,7 @@ var CodeView = function (_Component) {
2152021525
_react2.default.createElement(
2152121526
'p',
2152221527
{ key: i, className: 'line-number' },
21523-
i + 1
21528+
this.spaceFixedLineNumber(i + 1, lines.length)
2152421529
),
2152521530
_react2.default.createElement(
2152621531
_reactSyntaxHighlighter2.default,

src/components/CodeView.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ class CodeView extends Component {
1818

1919
scrollToSelected() {
2020
try {
21-
jq("body").animate({
22-
scrollTop: jq(".selected").offset().top - 500
21+
jq("body").animate({
22+
scrollTop: jq(".selected").offset().top - 500
2323
}, 750);
2424
} catch (e) {
2525
}
2626
}
2727

28+
spaceFixedLineNumber(curLine, totLines) {
29+
return "\u00a0".repeat(totLines.toString().length - curLine.toString().length) + curLine.toString()
30+
}
31+
2832
componentDidMount() {
2933
this.scrollToSelected();
3034
}
@@ -81,7 +85,7 @@ class CodeView extends Component {
8185
}}
8286
>
8387
<p key={i} className="line-number">
84-
{i + 1}
88+
{this.spaceFixedLineNumber(i + 1, lines.length)}
8589
</p>
8690
<SyntaxHighlighter language="python" style={tomorrowNight}>
8791
{line}
@@ -104,4 +108,4 @@ class CodeView extends Component {
104108
}
105109
}
106110

107-
export default CodeView
111+
export default CodeView

tracer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import time
1010

1111
last_call = None
12+
13+
1214
def debounce(wait):
1315
def decorator(fn):
1416
def debounced(*args, **kwargs):
1517
global last_call
18+
1619
def call_it():
1720
global last_call
1821
args, kwargs = last_call
@@ -25,14 +28,17 @@ def call_it():
2528
return debounced
2629
return decorator
2730

31+
2832
def log(msg):
2933
print('[LIVEPYTHON_TRACER] %s' % msg)
3034
sys.stdout.flush()
3135

36+
3237
@debounce(0.01)
3338
def log_frame(frame, should_update_source):
3439
log(json.dumps(generate_call_event(frame, should_update_source)))
3540

41+
3642
starting_filename = os.path.abspath(sys.argv[1])
3743
starting_dir = os.path.dirname(starting_filename)
3844

@@ -44,13 +50,15 @@ def log_frame(frame, should_update_source):
4450
current_locals = {}
4551
failed = False
4652

53+
4754
def get_module_name(full_path):
4855
global starting_filename
4956
return os.path.relpath(
5057
os.path.abspath(full_path),
5158
os.path.dirname(os.path.abspath(starting_filename))
5259
)
5360

61+
5462
def generate_call_event(frame, should_update_source):
5563
obj = {
5664
'type': 'call',
@@ -59,7 +67,8 @@ def generate_call_event(frame, should_update_source):
5967
'source': ''.join(linecache.getlines(frame.f_code.co_filename))
6068
}
6169
return obj
62-
70+
71+
6372
def generate_exception_event(e):
6473
return {
6574
'type': 'exception',
@@ -70,13 +79,14 @@ def generate_exception_event(e):
7079
'time': time.time()
7180
}
7281

82+
7383
def local_trace(frame, why, arg):
7484
global current_line
7585
global current_filename
7686

7787
if failed:
7888
return
79-
89+
8090
if why == 'exception':
8191
exc_type = arg[0].__name__
8292
exc_msg = arg[1]
@@ -101,9 +111,11 @@ def local_trace(frame, why, arg):
101111
log_frame(frame, should_update_source)
102112
return local_trace
103113

114+
104115
def global_trace(frame, why, arg):
105116
return local_trace
106117

118+
107119
with open(starting_filename) as fp:
108120
code = compile(fp.read(), starting_filename, 'exec')
109121

webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path')
22

33
module.exports = {
44
entry: './src/index.js',
5+
target: 'electron',
56
module: {
67
loaders: [
78
{ test: /\.js$/, loader: 'babel-loader', exclude: /(node_modules|main)/ }
@@ -10,5 +11,5 @@ module.exports = {
1011
output: {
1112
filename: 'bundle.js',
1213
path: path.resolve(__dirname, 'dist')
13-
}
14-
}
14+
},
15+
}

0 commit comments

Comments
 (0)