Skip to content

Commit

Permalink
line number fix
Browse files Browse the repository at this point in the history
  • Loading branch information
calumk committed Nov 24, 2024
1 parent 1ab71b4 commit 7312848
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/codecup.bundle.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
}

let demo_init = () => {
cup.enableLineNumbers()
cup.disableReadonlyMode()
cup.updateCode("Hello")
// cup.enableLineNumbers()
// cup.disableReadonlyMode()
cup.updateCode("Hello World")
}

let demo_create = () => {
Expand All @@ -60,7 +60,6 @@
maxLines : 15,
minLines : 5
});
demo_init();
}

let demo_dispose = () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calumk/codecup",
"version": "1.9.2",
"version": "1.9.3",
"description": "A micro code-editor for awesome web pages",
"main": "dist/codecup.bundle.js",
"files": [
Expand Down
21 changes: 16 additions & 5 deletions src/codecup.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class codecup {
}

createLineNumbers () {
// console.log('createLineNumbers')
this.elLineNumbers = this.createElement('div', this.elWrapper)
this.elLineNumbers.classList.add('codecup__lines')
this.elWrapper.classList.add('codecup--has-line-numbers')
Expand Down Expand Up @@ -117,7 +118,9 @@ export default class codecup {
destroyLineNumbers () {
this.elWrapper.classList.remove('codecup--has-line-numbers')
// console.log(this.elLineNumbers)
this.elLineNumbers.remove()
if (this.elLineNumbers) {
this.elLineNumbers.remove()
}
}

createElement (elementTag, whereToAppend) {
Expand All @@ -139,6 +142,9 @@ export default class codecup {
this.opts.maxLines = this.opts.maxLines || 100
this.opts.minLines = this.opts.minLines || 1


console.log(this.opts)

// this.opts.handleSelfClosingCharacters = this.opts.handleSelfClosingCharacters || false

// if handleTabs is not either true or false, make it true by default
Expand Down Expand Up @@ -166,10 +172,11 @@ export default class codecup {
this.elTextarea.setAttribute('autocorrect', 'off')
}

if (this.opts.lineNumbers) {
// this.elWrapper.classList.add('codecup--has-line-numbers')
// this.elWrapper.classList.add('codecup--has-line-numbers')
if(this.opts.lineNumbers){
this.createLineNumbers()
}


if (this.opts.defaultTheme) {
injectCss(defaultCssTheme, 'theme-default', this.opts.styleParent)
Expand All @@ -191,7 +198,9 @@ export default class codecup {
this.createCopyButton()
}

this.updateLineNumbersCount();
if (this.opts.lineNumbers) {
this.updateLineNumbersCount();
}

}

Expand Down Expand Up @@ -517,8 +526,10 @@ export default class codecup {
}

disableLineNumbers() {
if (this.opts.lineNumbers) {
this.destroyLineNumbers()
}
this.opts.lineNumbers = false;
this.destroyLineNumbers()
}

toggleLineNumbers(){
Expand Down

0 comments on commit 7312848

Please sign in to comment.